I would like to number the rows of a table that is inside another table. The aim is to create a single text file via a flow, where the nested tables appear as CSV inbetween some headers and footers.
Here's some example data to show how I sort by Account and Week (for the headers and footers), and then use a table called groupedItems that will be converted to CSV in a flow:
ClearCollect(
TestCollection,
{Account: "3090011",Week: 45,Project: "1102",Days: 13,rowNumber:0},
{Account: "3090013",Week: 46,Project: "2100",Days: 5,rowNumber:0},
{Account: "3090013",Week: 46,Project: "3102",Days: 2,rowNumber:0},
{Account: "3090013",Week: 46,Project: "4101",Days: 2,rowNumber:0},
{Account: "3090013",Week: 47,Project: "3102",Days: 9,rowNumber:0}
);
ClearCollect(
ForSorting,
AddColumns(
TestCollection,
"AccountWeek",
Account & ";" & Text(Week)
)
);
ClearCollect(SortedCollection,
AddColumns(
GroupBy(
ForSorting,
"AccountWeek",
"GroupedItems"
),
"Rows",
CountRows(GroupedItems),
"WeekGroup",
First(GroupedItems).Week,
"AccountGroup",
First(GroupedItems).Account
)
);
So in week 46 there are 3 rows that have the same account and week. How do i number these rows?
I've found some code that will incrementally number rows based on Patch, which I figure is what I need. Here's one such attempt that doesn't work:
ForAll(SortedCollection As parent,
With(
{records: parent.GroupedItems},
ForAll(
Sequence(CountRows(records)),
Patch(
Last(
FirstN(records,Value)
),
{rowNumber: Value}
)
)
)
);
(inspired by http://powerapps.co.nz/auckland/index.php/our-blog/35-add-row-numbers-to-a-power-apps-collection)