GroupBy Function
The GroupBy function returns a table with records grouped together based on the value of one or more columns. Records in the same group are placed into a single record, with a column added that holds a nested table of the remaining columns.
Power Apps Syntax GroupBy(Table, ColumnName1 [, ColumnName2, ... ], GroupColumnName )
- Table – It is a required parameter. It must be tabular data source. It specifies the Table to be grouped.
- ColumnName(s) – It is a required parameter. The column names in Table by which to group records. These columns become columns in the resulting table.
- GroupColumnName – It is a required parameter. The column name to be used for nested group data.
Example: Demonstration of the GroupBy function.
Step 1: There is a sharepoint list named ‘Group List’ created to demonstrate the use of GroupBy function in power apps.
Step 2: Add a vertical gallery in the canvas app. And set the Items property to the following power apps formula.
Power Apps Formula
Here,
- 'Group List': This represents the name of the data source or collection that we want to group.
- "Country": This is the column in the 'Group List' data source that we want to use as the basis for grouping. In this case, the function will group the records in 'Group List' based on unique values in the "Country" column.
- "MyData": This is the name we are assigning to the grouped data.
After applying the GroupBy function, the data is grouped by the "Country" column. The resulting grouped data will be stored with the column name "MyData".
Step 3: Add a Text label control and set its Text property to the following power apps formula.
Power Apps Formula
Step 4: Add another vertical gallery control inside the gallery itself to show the data which is grouped. As grouped data is in tabular form, and gallery support tabular data as a data source.
Power Apps Formula
Step 5: Add a Text label control and set its Text property to the following power apps formula.
Power Apps Formula
Step 6: Add another Text label control and set its Text property to the following power apps formula.
Power Apps Formula
Step 7: Now its time to preview the application.