Skip to content

Power Apps

Power Apps Generate Row Numbers In A Collection

Power Apps Generate Row Numbers In A Collection Posted by - Matthew Devaney on - August 22, 2022 18 Comments Generate row numbers for a Power Apps collection...

Matthew Devaney
Published
Reading time
3 min read

Before you start

Is this guide for you?

Best entry point
Power Apps
Time investment
3 min read

Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/power-apps-generate-row-numbers-in-a-collection/. Author: Matthew Devaney.

Power Apps Generate Row Numbers In A Collection Posted by - Matthew Devaney on - August 22, 2022 18 Comments

Generate row numbers for a Power Apps collection with this formula. Copy and paste this code into your own app. // Generate row number code

ClearCollect( colSolution, ForAll( Sequence(CountRows(colMyCollection)), Patch( Last(FirstN(colMyCollection, Value)), { RowNumber : Value} ) ) ) Code language: JavaScript ( javascript ) Here’s how it works:

The ForAll function returns a table of values with the row number included. First, we use the the CountRows function to determine how many rows are in the original collection and the Sequence function to generate the row number. Then we Patch the row numbers into the original collection and show them in a new column named RowNumber .

For more help with collections check out my Power Apps Collections Cookbook . There are over 50 examples and code you can copy + paste into your own apps. Full Example : Generate Row Numbers Input Collection

Start with this Power Apps collection named colVehicles . Year Make Model 2016 GM Yukon 2016 GM Yukon 2016 GM Yukon 2017 Nissan Frontier 2018 Chevy Silverado 2019 Honda Ridgeline 2020 Ford F150 2020 Ford F150 2020 Ford F150 2020 Ford F150 Output Collection

Our goal is to add the row numbers from the Power Apps collection colVehicles and achieve this result. RowNumber Year Make Model 1 2016 GM Yukon 2 2016 GM Yukon 3 2016 GM Yukon 4 2017 Nissan Frontier 5 2018 Chevy Silverado 6 2019 Honda Ridgeline 7 2020 Ford F150 8 2020 Ford F150 9 2020 Ford F150 10 2020 Ford F150 Solution Code

Use this code to remove the duplicate rows from colVehicles . //Create a collection

ClearCollect(colVehicles, { Year : 2016 , Make : "GM" , Model : "Yukon" }, { Year : 2016 , Make : "GM" , Model : "Yukon" }, { Year : 2016 , Make : "GM" , Model : "Yukon" }, { Year : 2017 , Make : "Nissan" , Model : "Frontier" }, { Year : 2018 , Make : "Chevy" , Model : "Silverado" }, { Year : 2019 , Make : "Honda" , Model : "Ridgeline" }, { Year : 2020 , Make : "Ford" , Model : "F150" }, { Year : 2020 , Make : "Ford" , Model : "F150" }, { Year : 2020 , Make : "Ford" , Model : "F150" }, { Year : 2020 , Make : "Ford" , Model : "F150" } ); // Generate row number code

ClearCollect( colSolution, ForAll( Sequence(CountRows(colVehicles)), Patch( Last(FirstN(colVehicles, Value)), { RowNumber : Value} ) ) ) Code language: JavaScript ( javascript ) Did You Enjoy This Article? 😺

Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?

If you have any questions about Power Apps Generate Row Numbers In A Collection please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. Matthew Devaney M365 Copilot Power Apps

How To Create Copilot Custom UI Widgets In Power Apps

Share this

Tagged

Collections · Power Apps

Have a Microsoft 365 topic idea?

Share article suggestions, community session ideas, corrections, or real-world scenarios for future nextM365 learning notes.

Suggest a topic

Keep learning Microsoft 365

Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.

Continue learning

Next action

What to do next

Browse all tutorials →