Filter by Date Range

If you’ve spent any time building business applications in Microsoft Power Apps, you already know that users almost immediately ask one question:

“Can I filter this by date?”

Whether it’s expense claims, leave requests, incident tickets, change records, or audit logs, date-based filtering is not a “nice to have” feature—it’s a baseline expectation. In fact, in production apps I’ve built for finance teams, HR, and operations, the absence of a date filter almost always leads to performance complaints or usability issues.

This article goes beyond a simple formula. I’ll walk you through:

  • How to correctly filter a gallery by date range
  • How to handle blank dates safely
  • What to watch out for with delegation
  • Real-world performance and usability lessons learned the hard way

This is written from the perspective of someone who has deployed Power Apps into real organisations, not just demo environments.


Understanding the Scenario

For this guide, we’ll assume:

  • Your app is connected to a data source such as SharePoint, Dataverse, or Excel
  • Your data source contains a date field
  • You are displaying records in a gallery
  • Users need to filter records between a start date and an end date

Example use cases I see frequently:

  • Finance filtering expenses for a reporting period
  • HR filtering leave requests by month or quarter
  • IT filtering incidents within an audit window
  • Managers reviewing approvals during a specific timeframe

Step 1: Prepare Your Data Source (This Is More Important Than It Looks)

Before touching Power Apps controls, confirm the following about your date column:

  • The column type is Date or Date & Time (not text)
  • The column is populated consistently
  • Time zones are understood (especially with SharePoint and Dataverse)

For this article, let’s assume:

  • Data source name: Expenses
  • Date column name: ExpenseDate

Real-world tip:
If your date field includes time (e.g., 2026-01-15 14:32), users filtering “up to today” may miss records later in the day. This catches people out constantly.


Step 2: Add DatePicker Controls for User Input

Insert two DatePicker controls onto your screen:

  • dpStartDate → Start of the range
  • dpEndDate → End of the range

Label them clearly:

  • “From Date”
  • “To Date”

Recommended Defaults (Based on Experience)

To reduce confusion and improve usability:

  • Set dpStartDate.DefaultDate to DateAdd(Today(), -30)
  • Set dpEndDate.DefaultDate to Today()

This gives users a sensible default window without forcing them to interact with the filters immediately.


Step 3: Add and Validate Your Gallery

Insert a Vertical Gallery and initially set:

Items = Expenses

Confirm:

  • Data loads correctly
  • The date field displays as expected
  • There are no delegation warnings yet

Only move on once you know your gallery works without filters.


Step 4: Apply a Basic Date Range Filter

Now for the core logic. Update the gallery’s Items property:

Filter(
    Expenses,
    ExpenseDate >= dpStartDate.SelectedDate &&
    ExpenseDate <= dpEndDate.SelectedDate
)

At a basic level, this works well and is often enough for small datasets or prototypes.

However, in production apps, this formula alone is not robust enough.


Step 5: Handle Blank Date Pickers Properly (Critical for Real Users)

Users will:

  • Clear a date accidentally
  • Only want “everything before X”
  • Only want “everything after Y”

If you don’t handle this, your gallery will appear empty and users will assume the app is broken.

Production-Safe Filter Formula

Filter(
    Expenses,
    (IsBlank(dpStartDate.SelectedDate) || ExpenseDate >= dpStartDate.SelectedDate) &&
    (IsBlank(dpEndDate.SelectedDate) || ExpenseDate <= dpEndDate.SelectedDate)
)

This ensures:

  • No start date → no lower limit
  • No end date → no upper limit
  • Both blank → show all records

Real-world lesson:
This single change dramatically reduces support tickets. I’ve seen apps fail user acceptance testing purely because empty filters weren’t handled.


Step 6: Reset Filters Cleanly

Add a Reset Filters button and set OnSelect:

Reset(dpStartDate);
Reset(dpEndDate)

Optionally, you can also:

  • Reset the gallery scroll position
  • Reapply default dates instead of blanks

Delegation: The Hidden Trap That Breaks Large Apps

This is where many Power Apps articles stop—and where real apps start to fail.

Why Delegation Matters

If your data source is SharePoint or Dataverse and contains more than 500–2000 records, Power Apps may:

  • Only filter a subset of data
  • Show incomplete results
  • Display delegation warnings

Is Date Filtering Delegable?

  • SharePoint: Yes, date comparisons can be delegable
  • Dataverse: Yes
  • Excel: No (avoid Excel for large datasets)

However, delegation breaks when:

  • You wrap the date field in functions like Text() or DateValue()
  • You compare against non-delegable expressions

Rule of thumb:
Always compare the raw date column directly to SelectedDate.


Performance Optimisation Tips from the Field

Here’s what I’ve learned after deploying multiple Power Apps at scale:

1. Pre-Filter at the Source Where Possible

If you know users only ever need the last year of data:

  • Filter the dataset early
  • Don’t load 10 years of history “just in case”

2. Avoid Time-Based Confusion

If your column includes time:

ExpenseDate < DateAdd(dpEndDate.SelectedDate, 1)

This ensures “end date” includes the entire day.

3. Combine Filters Carefully

Date filters often sit alongside:

  • Status filters
  • User filters
  • Department filters

Always test combinations—this is where delegation quietly breaks.


Common Mistakes I See Repeated

  • Treating date columns as text
  • Ignoring time components
  • Forgetting delegation warnings
  • Not handling blank date pickers
  • Letting users select an end date before a start date

You can prevent the last issue by setting:

dpEndDate.MinDate = dpStartDate.SelectedDate

Final Thoughts: Small Feature, Big Impact

Filtering a Power Apps gallery by date range might look trivial, but in real-world business apps it:

  • Improves performance
  • Increases usability
  • Reduces user frustration
  • Makes reporting practical

When implemented properly—with delegation awareness, edge-case handling, and sensible defaults—it becomes one of the most valuable features in your app.

If you’re building Power Apps for production use, don’t treat date filtering as an afterthought. Build it like your users depend on it—because they do.

Leave a Reply

Your email address will not be published. Required fields are marked *