Efficiently Filtering Dates in Power Apps Gallery for the Upcoming ‘n’ Days

Efficiently Filtering Dates in Power Apps Gallery for the Upcoming ‘n’ Days

Guide to Showcasing Dates Within the Next ‘n’ Days in Power Apps Gallery

Introduction:

With Power Apps, flexibility is at its core, and one common requirement is the ability to display dates from the upcoming ‘n’ days in a gallery. Whether you’re an app developer or a business user, this guide simplifies how you can dynamically filter dates in a gallery, based on a number you decide.

Data Source Overview

The source of dates, named ‘Calendar Records’, is derived from a SharePoint list which chronologically lists days from 1/1/2018 to 12/31/2024, summing up to 2,557 rows.

Title CalendarDate
Monday, January 1, 2018 1/1/2018
Tuesday, January 2, 2018 1/2/2018
Tuesday, December 31, 2024 12/31/2024

Implementing the Code

For gallery items filtering, apply the following code:


        With(
            {
                InitDate: Today(),
                FinalDate: DateAdd(Today(), 5, Days)  // Modify this value as needed
            },
            Filter(
                'Calendar Records',
                CalendarDate >= InitDate,
                CalendarDate <= FinalDate
            )
        )
    

Reference:

  1. With function
  2. Filter functions

Expected Outcome

Given the current date as 6/16/2021 and setting ‘n’ to 5, the gallery will precisely display dates from June 16th to June 20th, 2021. Here’s a glimpse:

  • Wednesday, June 16, 2021 – 6/16/2021
  • Thursday, June 17, 2021 – 6/17/2021
  • Friday, June 18, 2021 – 6/18/2021
  • Saturday, June 19, 2021 – 6/19/2021
  • Sunday, June 20, 2021 – 6/20/2021

Conclusion:

Power Apps empowers you to exhibit data tailored to specific needs. Filtering a gallery to show dates for an upcoming range is simplified with the method above. With a bit of code customization, you can set the range as per your requirements.

If challenges arise or there’s a need for a deeper understanding of this procedure or other technical aspects, please contact us. Our seasoned experts are ready to assist.

About The Author