The GroupBy function in Power Apps is used to group records from a table based on one or more columns. It returns a table where records are grouped together, and each group can be further processed. It’s useful when you need to summarize or categorize data within your app.
Syntax:
GroupBy(Table, ColumnName1, ColumnName2, ..., GroupColumnName)
- Table: Require. The table that contains the data to group.
- ColumnName1, ColumnName2: Required. The columns by which you want to group the data.
- GroupColumnName: Required. The name of the new column that will hold the grouped records.
Example of GroupBy function
Assume, you have a collection called colRegionalSales with the following columns:Â TranId, Region, ExecutiveId and Sales.

Now, you want to group the data by Region and create a new grouped column called GroupedSalesByRegion and store that data into new collection called colGroupedData.
Let’s add a button control, go to OnSelect property of button and write below formula.
ClearCollect(  colGroupedData,  GroupBy(    colRegionalSales,    Region,    SalesBy  ) )
- The formula groups all the records in the colRegionalSales collection based on the values in the Region column.
- The grouped data is then stored in a new column called SalesBy.
- After the grouping is done, the ClearCollect function clears any previous data from colGroupedData and stores the newly grouped data into the collection.
You can see, the formula groups the records based on the Region column and stores them in the new collection, colGroupedData.

Each SalesBy column contains a group of records for each respective Region. To see the records click on table icon, let’s click on North region.

Showing group records in a gallery
You can access the individual records within the nested tables created by the GroupBy function. In the formula above, GroupBy created a column named SalesBy, which holds a group of records for each corresponding region. These grouped records can be displayed in a gallery.
Let’s add a Gallery control. Set the Items property of the gallery to the grouped collection, colGroupedData, to display the group information. Within each group, you can then display the detailed records
You can see, Gallery displays the lists of Regions.

Now, to display the records for each group, Inside the gallery, add another nested gallery to display the records in the SalesBy column.
You can set the Items property of the nested gallery to the following formula.
ThisItem.SalesBy

ThisItem.Executive


![]()
