Power Apps Filter Gallery By Year

This Microsoft Power Apps tutorial explains everything about the Power Apps filter gallery by year.

Here, I will discuss how to filter a Power Apps gallery by the current year and how to filter a Power Apps gallery by next year.

Moreover, we will see the topics below:

  • Filter Power Apps gallery by next ‘N’ years
  • Filter Power Apps gallery by Previous year
  • How to filter a Power Apps gallery by previous ‘N’ years

Power Apps Filter Gallery By Current Year

I will show you how to filter a Power Apps gallery by the current year.

Example:

  • I have a SharePoint Online 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
  • In Power Apps, there is a Gallery control. This gallery displays each record from the SharePoint list based on the current Year.
Power Apps Gallery Filter By Current Year

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

Power Apps Filter Gallery By This Year
  • 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 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 fields 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.
How to Filter Power Apps Gallery By Current Year

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

Power Apps Filter Gallery By Next Year

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

Example:

  • I will also take the same SharePoint Online list [Travel Requests] for this example.
  • 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:

  • On the Power Apps Screen -> 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 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.
Power Apps Gallery Filter By Next Year

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’ Years.

Example:

  • I will take the same SharePoint Online list [Travel Requests] for this example.
  • In Power Apps, there is a Vertical Gallery control. This gallery filters and displays each record from the SharePoint list based on the next/upcoming two years.
Power Apps Gallery Filter By Next 'N' Years

To do so, follow the below steps.

  • On the Power Apps Screen -> 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 'N' Years
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Next 2 years records] like below.
Power Apps Filter Gallery By Next 'N' Years

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

Power Apps Filter Gallery By Last Year

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

Example:

  • I will take the same SharePoint Online list [Travel Requests] for this example.
  • In Power Apps, there is a Vertical Gallery control. This gallery displays each record from the SharePoint list based on the last or previous year.
Power Apps Filter Gallery By Previous Year

To achieve it, follow the below-mentioned steps. Such as:

  • On the Power Apps Screen -> 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] as in the below screenshot.
Power Apps Filter Gallery By Last Year

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

Power Apps Filter Gallery By Previous ‘N’ Years

Finally, I will show you how to filter a Power Apps gallery by previous ‘N’ years.

Example:

  • I will also take the same SharePoint Online list [Travel Requests] for this example.
  • In Power Apps, there is a Gallery control. This gallery displays each record from the SharePoint list based on the last/previous four years.
Power Apps Filter Gallery By Last 'N' Years

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

  • On the Power Apps Screen -> 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]
Power Apps Filter Gallery By Previous 'N' Years

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

Also, you may like some more Power Apps tutorials:

Conclusion

This Microsoft Power Apps tutorial taught us all about the Power Apps filter gallery by year. Here, I explained how to filter the Power Apps gallery by the current year and how to filter the Power Apps gallery by next year.

Also, we discussed the Power Apps filter gallery by the next/upcoming ‘N’ years and how to filter a Power Apps gallery by the previous year. Last, we covered how to filter a Power Apps gallery by previous ‘N’ years.