cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vsslasd
Advocate V
Advocate V

Insert Sequence Number Function into an Item Gallery

In an Gallery for the Item Property, I have the following definition:
ForAll(Filter(MR_POH,JobNo=Job_Gallery.Selected.JobNo &&
(Dropdown1.Selected.Value=Status || Dropdown1.Selected.Value="ALL")) As _item,
With(LookUp(
DropColumns(
AddColumns(
GroupBy('[dbo].[MR_POL]',"PackageNo","GroupedItems"),
"QTYSUM",Sum(GroupedItems,QTY)
),
"GroupedItems"),
PackageNo = _item.PackageNo),
Patch(_item,
{
QtySum: QTYSUM
})))

I'd like to include a sequential row number for each row using the Sequence function returned in above result set. 

Sequence function in Power Apps - Power Apps | Microsoft Docs

Thank you


 

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

It's not pretty, but if you have an items property set to the expression X, you can add an index to it using an expression similar to the one below:

 

With(
  { coll:X },
  ForAll(
    RenameColumns(Sequence(CountRows(coll)),"Value","Index") As Idx,
    Patch(Idx, Last(FirstN(coll, Idx.Index)))))

 

For your scenario, if you replace 'X' in the expression above with your original expression, you should get a new column called 'Index' in your gallery, something like the expression below:

With(
    { coll: ForAll(
        Filter(
            MR_POH,
            JobNo = Job_Gallery.Selected.JobNo && (Dropdown1.Selected.Value = Status || Dropdown1.Selected.Value = "ALL")) As _item,
        With(
            LookUp(
                DropColumns(
                    AddColumns(
                        GroupBy('[dbo].[MR_POL]', "PackageNo", "GroupedItems"),
                        "QTYSUM", Sum(GroupedItems, QTY)),
                    "GroupedItems"),
                PackageNo = _item.PackageNo),
            Patch(_item, { QtySum: QTYSUM })))
    },
    ForAll(
        RenameColumns(Sequence(CountRows(coll)),"Value","Index") As Idx,
        Patch(Idx, Last(FirstN(coll, Idx.Index)))))

Hope this helps!

View solution in original post

1 REPLY 1
CarlosFigueira
Power Apps
Power Apps

It's not pretty, but if you have an items property set to the expression X, you can add an index to it using an expression similar to the one below:

 

With(
  { coll:X },
  ForAll(
    RenameColumns(Sequence(CountRows(coll)),"Value","Index") As Idx,
    Patch(Idx, Last(FirstN(coll, Idx.Index)))))

 

For your scenario, if you replace 'X' in the expression above with your original expression, you should get a new column called 'Index' in your gallery, something like the expression below:

With(
    { coll: ForAll(
        Filter(
            MR_POH,
            JobNo = Job_Gallery.Selected.JobNo && (Dropdown1.Selected.Value = Status || Dropdown1.Selected.Value = "ALL")) As _item,
        With(
            LookUp(
                DropColumns(
                    AddColumns(
                        GroupBy('[dbo].[MR_POL]', "PackageNo", "GroupedItems"),
                        "QTYSUM", Sum(GroupedItems, QTY)),
                    "GroupedItems"),
                PackageNo = _item.PackageNo),
            Patch(_item, { QtySum: QTYSUM })))
    },
    ForAll(
        RenameColumns(Sequence(CountRows(coll)),"Value","Index") As Idx,
        Patch(Idx, Last(FirstN(coll, Idx.Index)))))

Hope this helps!

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.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

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 (6,202)