Are you facing any difficulties in showing a message if the gallery is empty in Power Apps? Follow this Power Apps tutorial to get all the information about how to show a message if a gallery is empty in Power Apps.
Here, we will discuss how to filter and display all SharePoint list records on a Gallery control using button controls and pop up a message when the Power Apps gallery is empty.
Show Message If Gallery is Empty in Power Apps
Let’s take a simple scenario: I have a SharePoint Online list named “Project Tracker” and this list contains the below fields.
- Title: Default single line of text
- Description: Multiple lines of text
- Status: Choice
- Start Date: Date and time
- End Date: Date and time
Now, I want to display these SharePoint list records on a gallery control based on the Choice field [Status] like below.
Also, I would like to show a message if the Power Apps gallery is empty, like “No Results Found” as in the Screenshot below.
To work around this, follow the below-mentioned steps. Such as:
1. Open Power Apps with your respective Microsoft credentials -> Create a Blank canvas app and connect it to the respective SharePoint list like below.
2. On the Power Apps Screen -> Insert a Gallery control and set Its Items property as:
Items = 'Project Tracker'
3. Then, insert three Button controls to filter the gallery control and set their OnSelect property to the code below.
OnSelect = Set(
gblFilterProjects,
Self.Text
)
Where,
- gblFilterProjects = Power Apps Global Variable Name
4. Now, filter the Power Apps gallery control using the button control selected value. For that, select the Gallery control and update the Items property code as:
Items = Filter(
'Project Tracker',
'Status'.Value = gblFilterProjects
)
- ‘Project Tracker’ = SharePoint Online list
- ‘Status’ = SharePoint list choice field
- gblFilterProjects = Power Apps global variable
5. Also, set the Visible property of a Gallery control as shown below.
Visible = !IsEmpty('Project Tracker') And !IsEmpty(
Filter(
'Project Tracker',
Status.Value = gblFilterProjects
)
)
Where,
- !IsEmpty() = This function helps us to test whether a table contains any record and it is equivalent to using the CountRows() function and checking for zero
- ‘Project Tracker’ = SharePoint list
6. Once it is done, click on the Preview button and click on the button controls to filter and display the SharePoint list records as in the screenshot below.
7. You can see below that there is an empty gallery control [When the user selects the In Progress button, it will give a blank gallery control]
8. Now, we need to show or pop up a message, i.e., [No Results Found], when the gallery is empty. To do so, insert a Text label and set its Text and Visible property as shown below
Text = "No Results Found"
Visible = CountRows(gal_Projects.AllItems)=0
Where,
- “No Results Found” = Label Text
- gal_Projects = Power Apps gallery name
- CountRows() = This function is used to count the number of records in a table
9. Same way insert a Search icon and set its Visible property to the code below.
Visible = CountRows(gal_Projects.AllItems)=0
10. Once your app is ready, Save, Publish, and Preview the app. Whenever a user selects an empty record gallery, it will show a message on the text label, as in the screenshot below.
This is all about how to show a message if a gallery is empty in Power Apps.
Conclusion
I hope this Power Apps tutorial explains how to show message if a gallery is empty in Power Apps. Like:
- How to retrieve the SharePoint list records on a Gallery control
- Filter and display SharePoint list records using button controls
- How to pop up a message when the Power Apps gallery is empty
You may like the following tutorials:
- How to Display SharePoint List Items in PowerApps Gallery?
- How to Sort Power Apps Gallery by Choice Column?
- Count Rows in Power Apps Gallery Control
- Power Apps Sort Gallery By Calculated Field
- How to Sort Power Apps Gallery By Month
- How to Delete SharePoint List Item from Power Apps Gallery?
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