Group The Items In A Power Apps Gallery

Group The Items In A Power Apps Gallery 

Group The Items In A Power Apps Gallery!

Overview:

In this guide, we’ll demonstrate how to group items in a Power Apps Gallery. You’ll learn how to use SharePoint lists and PowerApps to enhance your data presentation, beginning with setting up a SharePoint list and concluding with advanced PowerApps functionalities. By implementing these steps, users can better organize and display their data in the Power Apps interface.

Introduction: The Appointments App

Setting Up Your SharePoint List:

1. Access SharePoint:First, head to your SharePoint site where you’ll be creating the list. Ensure you have the required permissions.

2. Create a New List:

  • Start by clicking the “Settings” icon at the top-right.
  • Choose “Site contents” to see everything on the site.
  • Next, click “New” followed by “List.”
New Sharepoint List Creation for The Appointments App in PowerApps

3. Naming Your List:
Now, give your list a relevant name. For example, if it’s for storing product info, name it “Products.”

Naming the New Sharepoint List Creation for The Appointments App in PowerApps

4.Define List Columns: 

  • Here’s where you decide what information each product will have. For instance, you might have columns like “StartDate,” “FullName,” or “StreetAddress.”
Defining the column in a new Sharepoint List Creation for The Appointments App in PowerApps

Creating Your Canvas App:

1. Access PowerApps Portal:
  Open the Power Apps portal and sign in
2. Start from Scratch::
   Choose “Create” and then “Canvas app from blank.”

3. Designing the Interface:
   Begin crafting your app. You’ll want:

  • A clear and readable text label as your header.
  • Connection with your SharePoint list (follow the steps provided).
  • A gallery that shows your data (add this to your screen).
Connecting the data source with the new blank Canvas App in Powerapps

Please select the ‘Add Data’ button.

Connecting the data source with the new blank Canvas App in Powerapps step-2

Enter your query into the SharePoint search bar.

Connecting the data source with the new blank Canvas App in Powerapps step-3

Please enter the name of your desired list for retrieval.

4. Customize Gallery Content:

To show data in the gallery, add three text labels:

  • The first should have the input property: ThisItem.FullName
  • The second: ThisItem.StartDate
  • And the third: ThisItem.StreetAddress
    Insert a gallery into the screen and select “Your data source name” as the DataSource.

Add a text label for the header

Please incorporate a vertical gallery from the insertion options.

Insert a vertical gallery and data source in Canvas App in Powerapps

Integrate your data source with the gallery for seamless data visualization and management.

Add three text labels for show data in gallery. 

Add three text labels for show data in gallery in PowerApps

First label input property is. 

				
					ThisItem.FullName 

Second label input property is. 

ThisItem.StartDate 

And third input property is 

ThisItem.StreetAddress 
				
			
Customizing the three text labels for show data in gallery in PowerApps

Advanced PowerApps Functionalities:

Here’s where things get more advanced. You’ll be adding codes to buttons for specific functionalities like grouping items and displaying them properly.

1. Button for Testing:
    Make a new button and place it at the top of the title bar. We’re using this button for testing the code, and we’ll                remove it before we share the app. 

Please integrate this code into the ‘OnSelect’ event of the button

				
					ClearCollect( 

DailyAppointments, 

    AddColumns( 

        ShowColumns( 

            'Group The Items In A Power Apps Gallery', 

            "FullName", 

            "StartDate", 

            "StartDateTime", 

            "StreetAddress" 

        ), 

        "Level", 

        2 

    ) 

); 

 
				
			
A view of Gallery after customizing or putting code to the new button and place it at the top of the title bar in PowerApps

When you click the button, it creates a list of daily appointments in a specific order. We also add a ‘level’ column to distinguish between headings [1] and items [2] in the list. You’ll see why we do this shortly. 

Creating a list of daily appointments in a specific order by clicking the button

Next, we want to figure out a special list of appointment dates to use as headers in our grouped gallery. To do this, we add the following code to the button’s action. We use the DISTINCT function to make sure each date appears only once in the list, removing any duplicates from the “StartDateOnly” column. The result of the DISTINCT function is a list with one column, and we rename this column to “StartDateOnly.” Additionally, we create a new column called “Level” to identify each date as a header in our gallery. 

				
					// Create a collection of all daily appointments 

  

ClearCollect( 

DailyAppointments, 

    AddColumns( 

        ShowColumns( 

            'Group The Items In A Power Apps Gallery', 

            "FullName", 

            "StartDate", 

            "StartDateTime", 

            "StreetAddress" 

        ), 

        "Level", 

        2 

    ) 

); 

//// *** NEW CODE **** 

// Create a collection of all unique startdateonly values 

ClearCollect( 

    UniqueDates, 

    AddColumns( 

        RenameColumns( 

            Distinct( 

                'Group The Items In A Power Apps Gallery', 

                StartDate 

            ), 

            "Value", 

            "StartDate" 

        ).StartDate, 

        "Level", 

        1 

    ) 

); 
				
			
Customization or adding code to the button in PowerApps

Combine Group Headers And Group Items Into A Single Collection

The following code part is straightforward. We’re making a single collection named 

” CombinedAppointments ” that brings together the group titles and items into a single table. 

				
					ClearCollect( 

    DailyAppointments, 

    AddColumns( 

        ShowColumns( 

            'Group The Items In A Power Apps Gallery', 

            "FullName", 

            "StartDate", 

            "StartDateTime", 

            "StreetAddress" 

        ), 

        "Level", 

        2 

    ) 

); 

ClearCollect( 

    UniqueDates, 

    AddColumns( 

        RenameColumns( 

            Distinct( 

                'Group The Items In A Power Apps Gallery', 

                StartDate 

            ), 

            "Value", 

            "StartDate" 

        ).StartDate, 

        "Level", 

        1 

    ) 

);//// *** NEW CODE **** 

// Combine both collections into a single collection 

ClearCollect( 

    CombinedAppointments, 

    DailyAppointments, 

    UniqueDates 

); 
				
			
Combining the group titles and items into a single table or a collection in PowerApps

2. Grouping and Sorting:

Now, add the given code to the button’s action. This will let you group daily appointments by date and sort them.
The final thing we need to do is arrange the mixed-up collection in a way that puts the section titles at the top, followed by the items within each section. We can do this using the “Level” column we’ve been using. Just remember, a section title has a number 1, and an item inside a section has a number 2. 

				
					ClearCollect( 

    DailyAppointments, 

    AddColumns( 

        ShowColumns( 

            'Group The Items In A Power Apps Gallery', 

            "FullName", 

            "StartDate", 

            "StartDateTime", 

            "StreetAddress" 

        ), 

        "Level", 

        2 

    ) 

); 

ClearCollect( 

    UniqueDates, 

    AddColumns( 

        RenameColumns( 

            Distinct( 

                'Group The Items In A Power Apps Gallery', 

                StartDate 

            ), 

            "Value", 

            "StartDate" 

        ).StartDate, 

        "Level", 

        1 

    ) 

);//// *** NEW CODE **** 

// Combine both collections into a single collection 

ClearCollect( 

    CombinedAppointments, 

    DailyAppointments, 

    UniqueDates 

);//// *** NEW CODE **** 

// Sort the combined collection 

  

ClearCollect( 

    SortedAppointments, 

    SortByColumns( 

        'Group The Items In A Power Apps Gallery', 

        "StartDate", 

        "StartDateTime", 

        "StreetAddress", 

        "Level" 

    ) 

) 
				
			

Change The Gallery Datasource To The Grouped Collection

Now that we’ve got the data ready, we’ll put all the sorted appointments into the gallery. 

Changing The Gallery Datasource To The Grouped Collection as a comibined-appointments in PowerApps

3. Update Your Gallery:

After grouping and sorting your data, you need to display it in the gallery. Make sure you update the data source of the gallery.

We need to change how the gallery looks to show that the appointments are organized together. 

Insert a label  

Updating Gallery Formatting To Display Groups step-1

Please implement the code to display the current month in the designated label.”

Updating Gallery Formatting To Display Groups writing code in the label

Conclusion:

With the steps above, you can easily group items in a Power Apps Gallery. This improves data visualization, making information clearer and more organized. By combining SharePoint lists and PowerApps, users can create powerful, easy-to-read apps.

If you want to learn more about the Power Apps, feel free to explore our other informative articles and tutorials.

Have additional inquiries? Our team is here to assist. Please don’t hesitate to reach out!

About The Author