Live Developer Training: next batch coming soon. Be the first to know.Live training: next batch soonJoin the waitlist →Join →

Power Apps Filter Gallery By Year [With Real Examples]

This Power Apps tutorial will guide you on working with Power Apps Filter Gallery By Year using various scenarios.

Also, we will discuss how to filter Power Apps Gallery by Last Year, how to filter Power Apps Gallery by Last N Years, and many more like:

  • Power Apps Filter Gallery By Current Year
  • Power Apps Filter Gallery By Next Year
  • Power Apps Filter Gallery By Next N Years

Check out: Power Apps Gallery Control Examples Download [20 Various Real Scenarios]

Set up a SharePoint List

I have used a SharePoint list IT Help Desk for all the above examples. This list has these many columns (with different data types):

ColumnsData types
Request IDNumber
SubjectSingle line of text (This is a Title column, I just renamed it to Subject)
Request DateDate and time
CategoryChoice [Servers, User Workstation, Basic Software, Data Center, None]
PriorityChoice [Very High, High, Normal, Medium, Low, Very Low]

Also, this list has some records, as shown in the below screenshot:

Power Apps Filter Gallery Control By Year

Now we will explore all the examples one by one.

Power Apps Filter Gallery By Year

In the first example, we will see how to work with Power Apps Filter Gallery By Year.

  • The image below represents a Power Apps Gallery Control and a Dropdown Control. When a user selects any particular year from the dropdown menu, the gallery will filter and display only those specific dropdown-selected year records.
  • For example, if I chose the year 2022, the gallery filtered and displayed all of the records for that year.
Power Apps Filter Gallery By Year
  • First, we must retrieve all the years from the SharePoint list Date column to a Power Apps Dropdown control.
  • Insert a Dropdown control and set its Items property as:
Items = Distinct(
    'IT Help Desk',
    Year('Request Date')
)

Where,

  1. ‘IT Help Desk‘ = SharePoint List Name
  2. ‘Request Date‘ = SharePoint Date Column

NOTE:

However, I would advise against filtering your sharepoint list directly as you would get delegation problems after 2000 rows of data.

To overcome this, apply the code below on Screen’s OnVisible property:

OnVisible = ClearCollect(ColYear, 'IT Help Desk')

Then, select the Dropdown control and set its Items property as:

Items = Distinct(ColYear, Year('Request Date'))
The above codes will avoid the Power Apps delegation issues.
Power Apps Gallery Filter By Year
  • Next, select the gallery and apply the code below on its Items property as:
Items = Filter(
    'IT Help Desk',
    Year('Request Date') = ddSelectYear.Selected.Value
)

Where,

ddSelectYear = Dropdown Control Name

PowerApps Filter Gallery By Year
  • Save, Publish, and Close the app. Play the app again and select a year from the dropdown menu. You will see the gallery will appear with only that specific year-filtered records.

This is how to work with Power Apps Filter Gallery By Year.

Power Apps Filter Gallery By Last Year

Next, we will see how to filter Power Apps Gallery by last/previous year.

  • Since my current date is “8/22/2023,” the Power Apps Gallery below shows all the data from the previous year, or 2022.
Power Apps Filter Gallery By Last Year
  • To work around this, select the gallery and apply the formula below on its Items property:
Items = Filter(
    'IT Help Desk',
    'Request Date' >= Date(
        Year(Today()) - 1,
        1,
        1
    ),
    'Request Date' <= Date(
        Year(Today()) - 1,
        12,
        31
    )
)

OR

Items = With(
    {
        FirstDate: Date(
            Year(Today()) - 1,
            1,
            1
        ),
        LastDate: Date(
            Year(Today()) - 1,
            12,
            31
        )
    },
    Filter(
        'IT Help Desk',
        'Request Date' >= FirstDate,
        'Request Date' <= LastDate
    )
)

We can use any of the above formulas.

Where,

  1. ‘IT Help Desk‘ = SharePoint List Name
  2. ‘Request Date‘ = SharePoint Date Column
  3. FirstDate, LastDate = Scope variable names

Refer to the below screenshot.

Power Apps Filter Gallery By Previous Year

This is how to filter Power Apps Gallery by last year.

Power Apps Filter Gallery By Last N Years

Suppose you want to filter the Power Apps Gallery by the last N Years. Then follow the example below.