Accessing a Group Inside of a Collection

Sometimes you will want to group your data by a specific attribute and show that data in PowerApps. One way to do this is by creating two separate tables and have them grouped before PowerApps, but another way is by grouping a collection inside PowerApps.

In the example below, I will be grouping NFL players into their teams so I can create a gallery within a gallery to scroll and see the list of player names.

First, you want to group your data. When you create a group, you’re creating a parent for the records in your data source. I created a button to do this:


The syntax for using the function GroupBy is:

GroupByTableColumnName1 [, ColumnName2, … ], GroupColumnName )

You can GroupBy multiple columns, but for this example I will be just grouping by teams.

Below is how your collection will look like when you’re grouping:

If you click the squares that are under the “Players” column, you’ll see a whole new table with three columns. From the way I see it, “Players” is a collection inside of the “PlayersbyTeam” collection.

Then, you create a gallery for your collection.

Add a label for your groups. Here, “Team” is column name for the groups in the collection.

Insert another gallery into the gallery, and use a filter on that gallery to filter for the teams.

Filter(Players,ThisItem.Team = Team)

Insert labels into the gallery you just created, and change the label text to the column that is in the group.

You can use CountRows and Filter functions on your data:

CountRows(Filter(Players,Pos = “QB”))

The only filter you need to do is on the positions because the function will already know to pull from that specific team. As you can see, all teams have 75 players and 4 quarterbacks, but the amount of centers (C), offensive tackles (OT), and offensive guards (OG) are different.

And it will come out like this: