cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AngeloLopes
Resolver I
Resolver I

Sequence not working properly.

I have a App where Models have Operations and so on...

What I'm trying to do is to send a Model's Operations to a collection, along with a new column called "order".

The main objective of the column is so that when the collection is put on a gallery, it will have 2 buttons, Up and Down, where it re-orders the position of the item using the order column.

 

To do that, I used the sequence function to create a sequence of numbers from 1 to the Count of Rows that the collection has, so if the collection has 4 rows, the order column will be 1 - 2 - 3 - 4 .

 

The problem is that the Order column is not working properly, as seen in the picture below:

AngeloLopes_0-1658334257943.png

 

The Sequence function itself is working, but the way it is placed on the collection is why I am here.

As you can see the Order column has 1 - 2 - 3, because the Model that it came from had 3 Operations, hence the 1 - 2 - 3.

 

AngeloLopes_1-1658334340749.png

 

So that's the problem, I need to find the correct syntax that doesn't cause that error.

Here is my code:

ClearCollect(colModOp;Filter('Modelos&Operações';ThisItem.ID = RefIDModelo);{Ordem:Sequence(CountIf('Modelos&Operações';ThisItem.IDModelo = RefIDModelo))});;

 

Any help would be awesome 😁

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Drrickryp
Super User
Super User

@AngeloLopes 

With(
    {records: Filter('Modelos&Operações';ThisItem.ID = RefIDModelo)},//your filter and sort
    ClearCollect(
        colModOp;
        ForAll(
            Sequence(CountRows(records));
            Patch(
                Index(
                    records,
                    Value
                ),
                {rowNumber: Value}
            )
        )
    )
)

View solution in original post

3 REPLIES 3
Drrickryp
Super User
Super User

@AngeloLopes 

With(
    {records: Filter('Modelos&Operações';ThisItem.ID = RefIDModelo)},//your filter and sort
    ClearCollect(
        colModOp;
        ForAll(
            Sequence(CountRows(records));
            Patch(
                Index(
                    records,
                    Value
                ),
                {rowNumber: Value}
            )
        )
    )
)
AngeloLopes
Resolver I
Resolver I

IT WORKS, THANK YOU SO MUCH!!!

 

Now it's just patching between the row numbers and my Re-Order buttons can work!

AngeloLopes
Resolver I
Resolver I

Hey, @Drrickryp !

 

I have a question. I am using your formula to create a Re-Order button (Up and Down) to manually sort the Items of a gallery. But if I just stay by the normal Patch + 1 and Patch - 1, there will be cloned Order numbers.

I tried to make this way:

Patch(colModOp;ThisItem;{Ordem:ThisItem.Ordem + 1});;
Patch(colModOp;LookUp(colModOp; ThisRecord.Ordem = ThisItem.Ordem + 1;ThisRecord);{Ordem: ThisItem.Ordem - 1})

(This is for the down arrow, swapping the operators gives you the up arrow.)

 

What I mean by that code is that the Item you are currently on has a Order of 1, and the next one is 2. Supposedly, the could should've make the 1 be 2 and the 2 be 1. But It seems to make things worse.

 

Any tips to make this more bugless? 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,098)