If you want to group the Power Apps data table records, you can easily do that using the Power Apps GroupBy() function.
In this Power Apps tutorial, I will explain the Power Apps data table group with real-time examples like:
- Power Apps Data Table Group By Column
- How to group Power Apps data table using multiple columns
- Working with Power App data table group by filter
- Power App Data Table Group By Sum
- How to ungroup the Power Apps data table
Power Apps Data Table Group By
We can group the Power Apps data table to organize our data based on specific requirements. For example, you can group a list of Project tasks by their status (e.g., “In Progress,” “Completed,” “Pending”) to provide a more structured and organized view for better understanding.
Using the GroupBy() function in the Power Apps Data table, you can easily group data based on one or more columns in your data source [SharePoint, Excel, Collection, etc…].
Power Apps GroupBy() Syntax:
GroupBy(Table, ColumnName1[ColumnName2, ... ], GroupColumnName)
Where,
- Table = It is required, and it will be grouped
- ColumnName (s) = We can create a group based on the column names
- GroupColumnName = It stores the group records like a nested table
If you want more information about grouping the Power Apps data table, follow the scenarios below. Such as:
- Power Apps Data Table Group By Column
- How to Group the Power Apps Data Table using Multiple Columns
- Power App Data Table Group By Filter
- Power App Data Table Group By Sum
- Working with Power Apps Data Table UnGroup
Let me explain one by one.
Power Apps Data Table Group By Column
I have a SharePoint Online list [Expense Tracker], this list contains the different columns with various data types.
Input:
Column Name | Data Type |
Expense Name | It is a default single line of text column |
Expense Type | Choice |
Budget | Choice |
Amount | Number |
I want to group this text field [Expense Name], and all the Expense names will appear in the Power Apps data table control.
Output:
To do so, follow the below steps.
1. Create a Blank Canvas app and connect it to the specific SharePoint list -> Select the Power Apps Screen -> Insert a Data table control and use the below code to set its Items property.
Items = GroupBy(
AddColumns(
'Expense Tracker',
"ExpenseName",
Title
),
"ExpenseName",
"GroupByExpenses"
)
Where,
- ‘Expense Tracker’ = SharePoint Online list
- “ExpenseName” = New column name
- Title = SharePoint list text field
- “GroupByExpenses” = Group name
2. Save, Publish, and Preview the app. The Power Apps data table displays the group records from the SharePoint list based on the text field column as shown below.
Group Power Apps Data Table using Multiple Columns
1. In the above example, we saw how to group the Power Apps data table using a single column. I will show you how to group the data table using multiple columns.
2. Here also I will take the above SharePoint list. Insert a Button control and set its OnSelect property as:
OnSelect = ClearCollect(
colMultipleColumns,
GroupBy(
'Expense Tracker',
"Title",
"Description",
"Date",
"Amount",
"ExpenseGroup"
)
)
Where,
- colMultipleColumns = Collection name
- “Title”, “Description”, “Date”, etc… = SharePoint list columns which we want to group in the data table
3. Now, insert a Data table and set its Items property as:
Items = colMultipleColumns
4. Whenever the user clicks on the button control, the data table displays the grouped records based on the multiple columns.
Have a look at the below screenshot for the output.
Power App Data Table Group By Filter
Let’s see how to filter and group the Power Apps data table. Select the data table and provide the code below to its Items property.
Items = GroupBy(
Filter(
'Expense Tracker',
"Within Budget" exactin Budget.Value
),
"Title",
"Amount",
"GroupByBudget"
)
Where,
- Budget, Title, Amount = SharePoint list fields
Once it is done, look at the out for how to filter and display the data table records based on the SharePoint list choice field value.
Power App Data Table Group By Sum
In this section, I will explain how to group the Power Apps data table using the Sum() function with a simple scenario:
Scenario:
I have a Power Apps collection[colTravel], containing different fields, including two number columns [Estimated Airfare & Estimated Hotel Cost].
Now, I would like to display grouped record [TotalCost] in the data table using a sum of two collection number fields. For that, insert a data table and set its Items property as:
Items = GroupBy(
AddColumns(
colTravel,
"TotalCost",
TripTitle & " - " & Sum(
EstimatedAirfare,
EstimatedHotelCost
)
),
"TotalCost",
"GroupByTotal"
)
Where,
- colTravel = Power Apps collection name
- “TotalCost” = New column name
Once your app is ready, Save, Publish, and Preview the app. The data table groups and displays the records based on the sum of the two collection number fields like below.
How to UnGroup Power Apps Data Table
In the last, let me show you how to ungroup the Power Apps grouped data table. To achieve it, insert a Button control and set its OnSelect property to the code below.
OnSelect = ClearCollect(
colUngroup,
Ungroup(
colMultipleColumns,
"ExpenseGroup"
)
)
Where,
- colUngroup = Power Apps new collection name
- colMultipleColumns = Name of the grouped collection
Next, insert a Data table control and set its Items property as:
Items = colUngroup
Now, whenever the user clicks on the button control, the data table displays ungroup records as in the screenshot below.
If you have any requirements to work on the Power Apps data table group items, I hope you find this article helpful. This article taught in detail information about how to group the Power Apps data table with different and useful scenarios.
Also, you may like some more Power Apps articles:
- Power Apps Data Table Default Select Row
- Hide a Column in Power Apps Data Table
- How to Make Power Apps Data Table Empty
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com