Mastering Power Apps: How to Filter a Gallery by Date Range
Filtering data by date range is a common requirement in business applications, and Microsoft Power Apps makes this task relatively straightforward with the right components and formulas. Whether you’re creating a leave tracker, expense manager, or sales dashboard, adding date range filters to your galleries gives users more control and insight.
In this tutorial, we’ll walk through how to set up a date range filter in a Power Apps gallery using two DatePicker controls and the Filter function.
Step 1: Set Up Your Data Source
Before you begin, make sure your app is connected to a data source that includes a date field. This could be SharePoint, Excel, Dataverse, or any other supported connector. Let’s assume your data source is called Expenses and the date field is named ExpenseDate.
Step 2: Add Date Picker Controls
To allow users to select the start and end dates of their filter, add two DatePicker controls to your screen:
- Name the first one
dpStartDate - Name the second one
dpEndDate
Label them appropriately so users understand their purpose (e.g., “Start Date” and “End Date”).
Step 3: Add the Gallery
Insert a Gallery control that displays items from your data source. For example, a vertical gallery showing the Expenses data. Set the Items property of the gallery to your data source initially to ensure it’s working.
Items: Expenses
Step 4: Apply the Filter Formula
Now update the Items property of the gallery to filter the data based on the selected date range:
Filter(
Expenses,
ExpenseDate >= dpStartDate.SelectedDate &&
ExpenseDate <= dpEndDate.SelectedDate
)
This formula tells Power Apps to only show records where the ExpenseDate falls between the selected start and end dates.
Step 5: Add a Reset Button (Optional)
To enhance usability, you can add a Button that resets the date filters. Set the OnSelect property to:
Reset(dpStartDate);
Reset(dpEndDate)
This will clear the date pickers and return the gallery to an unfiltered state.
Step 6: Handle Edge Cases
Sometimes users may leave one or both date pickers blank. To make your filter more robust, you can modify the formula to include checks:
Filter(
Expenses,
(IsBlank(dpStartDate.SelectedDate) || ExpenseDate >= dpStartDate.SelectedDate) &&
(IsBlank(dpEndDate.SelectedDate) || ExpenseDate <= dpEndDate.SelectedDate)
)
This version ensures that if either date is not selected, it won’t restrict the results unnecessarily.
Final Thoughts
Filtering a Power Apps gallery by date range is a valuable technique for creating dynamic, user-friendly applications. With just a couple of DatePicker controls and a simple formula, you can empower users to dig deeper into your app’s data.
Whether you’re building productivity tools or business dashboards, this feature adds flexibility and professionalism to your solutions.
