Live Developer Training: next batch coming soon. Be the first to know.Live training: next batch soonJoin the waitlist →Join →

How to Use Power Apps Collection GroupBy?

Are you interested in learning how to use a Power Apps collection GroupBy? In this Power Apps tutorial, I will explain everything related to the Power Apps collection GroupBy. Such as:

  • Power Apps Collection UnGroup
  • Power Apps Collection Filter GroupBy
  • Working with Power Apps Collection Group Aggregate Results

Power Apps Collection GroupBy()

The Power Apps GroupBy() function is a useful tool to group records in a table based on values in one or more columns.

Moreover, we can group all the records into a single entry that could serve as a nested table within the Power Apps collection.

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

For example: I have two Power Apps collections, i.e., [colPatients] and [colDiseases], as in the screenshot below.

The first collection contains the below headers/columns.

Column NameData Type
PatientIDText
PatientNameText
DateOfBirthDate and time
DiseaseText
DoctorPerson
Power Apps Collection GroupBy

Once the nested table [GroupDiseases] is clicked, it will display the grouped records as shown below.

How to Use Power Apps Collection GroupBy

To work around this, follow the below-mentioned steps. Such as:

1. Open Power Apps with your credentials -> Create a Blank canvas app -> Select App object [From left navigation] and set its OnStart property to the code below.

OnStart = ClearCollect(
    colPatients,
    {
        PatientID: "SP001",
        PatientName: "Richard",
        DateOfBirth: "10/1/1995",
        Disease: "Influenza",
        Doctor: "Store Kane",
        DoctorFees: 2000,
        TotalFees: 5000
    },
    {
        PatientID: "SP002",
        PatientName: "Steven Rock",
        DateOfBirth: "2/17/2001",
        Disease: "Malaria",
        Doctor: "Chelsi Cooley",
        DoctorFees: 1000,
        TotalFees: 4000
    },
    {
        PatientID: "SP003",
        PatientName: "Lynee",
        DateOfBirth: "9/21/1998",
        Disease: "Lyme disease",
        Doctor: "Herman Boykin",
        DoctorFees: 1200,
        TotalFees: 4500
    },
    {
        PatientID: "SP004",
        PatientName: "Rosi Marky",
        DateOfBirth: "12/7/2000",
        Disease: "Malaria",
        Doctor: "Store Kane",
        DoctorFees: 1500,
        TotalFees: 5500
    },
    {
        PatientID: "SP005",
        PatientName: "Aaman Roy",
        DateOfBirth: "11/1/2002",
        Disease: "Malaria",
        Doctor: "Richard rone",
        DoctorFees: 2500,
        TotalFees: 5800
    }
)

Where,

  • colPatients = Power Apps Collection Name
  • PatientID, PatientName, DateOfBirth, etc… = Collection Headers/Columns
  • “SP001”, “Richard”, “10/1/1995”, etc… = Collection Records/Rows
How to Use GroupBy Power Apps Collection

2. Next, click on the App more commands (…) option and click on the Run OnStart option to get our collection.

3. Then, go to the Variables section -> Expand Collections drop-down to find collections, as shown below.

How to Use a GroupBy Power Apps Collection

4. Here, we need to group the two columns into a single record and add a nested table to display the records in another collection [colDiseases]. To do so, Add a Button control on the screen and set its OnSelect property to the code below:

OnSelect = ClearCollect(
    colDiseases,
    GroupBy(
        colPatients,
        "Disease",
        "Doctor",
        "DoctorFees",
        "GroupDiseases"
    )
)

Where,

  • colDiseases = Collection name
  • GroupBy = This function helps us to group the multiple records in a single record
  • colPatients = Power Apps source collection
  • “Disease”, “Doctor”, and “DoctorFees” = These are the columns which we want to group
  • “GroupDiseases” = It is the name of the nested table
Power Apps GroupBy Collection

5. Now, Save, Publish, and Preview the app. When the user clicks on the Button control, the collection will added under the variable section.

6. Once you click on any nested table [GroupDiseases] you will get the grouped data with respected columns, as in the screenshot below.