How to Filter Power Apps Gallery By Year?

In my recent Power Apps application, I have used a gallery control containing some records from the SharePoint list. I wanted to filter the gallery data by the current and previous years.

In this article, I will explain how to filter Power Apps gallery by year, including the current year, the previous year, and the upcoming years.

In addition, we will also discuss filtering the Power Apps gallery by the next N years and previous N years with various scenarios.

Filter Power Apps Gallery By Current Year

Let’s discuss how to filter the gallery by current year in Power Apps.

Example:

I have a SharePoint List named Travel Requests. This list contains the below fields.

Column NameData Type
Trip TitleThis is a Title column with a single line of text. I just renamed it to “Trip Title”
DestinationChoice
Travel Start DateDate and time
Travel End DateDate and time
Refer to the below screenshot:
Power Apps Filter Gallery By Year
Power Apps Gallery Filter By Current Year

To achieve the above example, follow the below steps. Such as:

  • Insert a Gallery control [gal_CurrentYearTrips] and set its Items property to the code below.
Items = With(
    {
        StartDate: Date(
            Year(Today()),
            1,
            1
        ),
        EndDate: Date(
            Year(Today()),
            12,
            31
        )
    },
    Filter(
        'Travel Requests',
        'Travel Start Date' >= StartDate,
        'Travel End Date' <=  EndDate
    )
)

Where,

  1. With() = This function can help us to evaluate a formula for a single record
  2. StartDate, EndDate = Power Apps Scope Variables
  3. Date() = This function is used to convert individual Year, Month, and Day values to a Date/Time value
  4. Year() = This function returns the year component of a Date/Time value
  5. Today() = Power Apps Today() helps to get the current date
  6. ’12’, ’31‘ = 12 for the number of months and 31 for the number of days in a month
  7. ‘Travel Requests’ = SharePoint Online List
  8. ‘Travel Start Date’, ‘Travel End Date’ = SharePoint date columns
Power Apps Gallery Filter By This Year
  • SavePublish, and Preview the app. The gallery will display the filtered records, i.e., [Current Year Records], as in the screenshot below.

This is how to filter a Power Apps gallery by the current year.

Filter Power Apps Gallery By Next Year

Next, we will see how to filter a Power Apps gallery by the next or upcoming year.

  • In Power Apps, there is a Horizontal Gallery control. This gallery displays each record from the SharePoint list based on the next or upcoming year.

Refer to the below image:

Power Apps Filter Gallery By Next Year

To work around this example, follow the below-mentioned steps. Such as:

  • Insert a Gallery control and set its Items property as:
Items = With(
    {
        StartDate: Date(
            Year(Today())+1,
            1,
            1
        ),
        EndDate: Date(
            Year(Today())+1,
            12,
            31
        )
    },
    Filter(
        'Travel Requests',
        'Travel Start Date' >= StartDate,
        'Travel End Date' <= EndDate
    )
)

Where,

  1. Year(Today())+1 = This function returns the year component of a Date/Time value, whereas ‘1’ is used for the next year
Power Apps Filter Gallery By Upcoming Year
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Next Year Records], shown below.

This is how to filter a Power Apps gallery by next/upcoming year.

Power Apps Filter Gallery By Next N Years

Let’s see how to filter the Power Apps gallery by the next N number of Years.

  • In Power Apps, there is a Vertical Gallery control. This gallery filters and displays each record from the SharePoint list based on the next two years from the current year.
Power Apps Gallery Filter By Next &#039;N&#039; Years

To do so, follow the below steps.

  • Insert a Gallery control and set its Items property to the code below.
Items = With(
    {
        StartDate: Date(
            Year(Today()),
            Month(Today()),
            Day(Today())
        ),
        EndDate: Date(
            Year(Today()) + 2,
            Month(Today()),
            Day(Today())
        ) - 1
    },
    Filter(
        'Travel Requests',
        'Travel Start Date' >= StartDate,
        'Travel End Date' <= EndDate
    )
)

Where,

  1. Year(Today()) = This function returns the year component of a Date/Time value
  2. Month(Today()) = This function returns the month component of a Date/Time value
  3. Year(Today()) + 2 = 2 is number of next years // You can change No of years

Refer to the below screenshot:

Power Apps Filter Gallery By Upcoming &#039;N&#039; Years
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Next 2 years records], as shown below.

This is all about how to filter a Power Apps gallery by the next/upcoming N years.

Filter Power Apps Gallery By Last Year

Similarly, here we will see how to filter a Power Apps gallery by the previous year.

  • In the screenshot below, you can see the Power Apps gallery displays each record from the SharePoint list based on the last or previous year.
Power Apps Filter Gallery By Previous Year
  • Insert a Gallery control and set its Items property as:
Items = With(
    {
        StartDate: Date(
            Year(Today())-1,
            1,
            1
        ),
        EndDate: Date(
            Year(Today())-1,
            12,
            31
        )
    },
    Filter(
        'Travel Requests',
        'Travel Start Date' >= StartDate,
        'Travel End Date' <= EndDate
    )
)

Where,

  1. Year(Today())-1 = This function returns the year component of a Date/Time value, and ‘1’ is used for the previous/last year

Refer to the below image:

Power Apps Gallery Filter By Last Year
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Last Year Records].

This is how to filter a Power Apps gallery by last year.

Filter Power Apps Gallery By Previous N Years

Finally, I will show you how to filter a Power Apps gallery by previous N years (for example last 4 years data).

  • The below Power Apps gallery displays each record from the SharePoint list based on the previous four years.
Power Apps Filter Gallery By Last &#039;N&#039; Years

To work around the above example, follow the below steps.

  • Insert a Gallery control and set its Items property code like below.
Items = With(
    {
        StartDate: Date(
            Year(Today())-4,
            Month(Today()),
            Day(Today())
        )+ 1,
        EndDate: Date(
            Year(Today()),
            Month(Today()),
            Day(Today())
        )
    },
    Filter(
        'Travel Requests',
        'Travel Start Date' >= StartDate,
        'Travel End Date' <= EndDate
    )
)

Where,

  1. Year(Today())-4 = This function returns the year component of a Date/Time value, and 4 is the number of previous years // You can change the number of years

Refer to the below screenshot:

Power Apps Gallery Filter By Previous 'N' Years
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Last Four Years Records]

This is all about the Power Apps filter gallery by previous/last N years.

Also, you may like some more Power Apps tutorials:

I hope this article helped you to learn how to filter Power Apps gallery by current year, next year, previous year.

Additionally, we saw how to filter Power Apps gallery by next N years and previous N years with examples.

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…