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):
Columns | Data types |
---|---|
Request ID | Number |
Subject | Single line of text (This is a Title column, I just renamed it to Subject) |
Request Date | Date and time |
Category | Choice [Servers, User Workstation, Basic Software, Data Center, None] |
Priority | Choice [Very High, High, Normal, Medium, Low, Very Low] |
Also, this list has some records, as shown in the below screenshot:
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.
- 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,
- ‘IT Help Desk‘ = SharePoint List Name
- ‘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:
The above codes will avoid the Power Apps delegation issues.Items = Distinct(ColYear, Year('Request Date'))
- 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
- 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.
- 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,
- ‘IT Help Desk‘ = SharePoint List Name
- ‘Request Date‘ = SharePoint Date Column
- FirstDate, LastDate = Scope variable names
Refer to the below screenshot.
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.
- The Power Apps Gallery contains all the records based on the last three years [from the SharePoint list], i.e., 2023, 2022, and 2021. Here, my current date is “8/22/2023,”
- To do so, select the gallery and set its Items property to the formula below:
Items = With(
{
FirstDate: Date(
Year(Today()) - 3, // Specify this number
Month(Today()),
Day(Today())
) + 1,
LastDate: Date(
Year(Today()),
Month(Today()),
Day(Today())
)
},
Filter(
'IT Help Desk',
'Request Date' >= FirstDate,
'Request Date' <= LastDate
)
)
Where,
- ‘IT Help Desk‘ = SharePoint List Name
- ‘Request Date‘ = SharePoint Date Column
- FirstDate, LastDate = Scope variable names
This is how to filter Power Apps Gallery by the last N years.
Power Apps Filter Gallery By Current Year
In this scenario, we will discuss how to work with Power Apps Filter Gallery By Current Year.
- The below Power Apps Gallery control displays all the current year records since my current date and year is “8/22/2023“.
- To achieve this, write the formula below on the gallery’s Items property as:
Items = With(
{
FirstDate: Date(
Year(Today()),
1,
1
),
LastDate: Date(
Year(Today()),
12,
31
)
},
Filter(
'IT Help Desk',
'Request Date' >= FirstDate,
'Request Date' <= LastDate
)
)
Where,
- ‘IT Help Desk‘ = SharePoint List Name
- ‘Request Date‘ = SharePoint Date Column
- FirstDate, LastDate = Scope variable Names
This is how to work with the Power Apps filter gallery by the current year.
Power Apps Filter Gallery By Next Year
The example below will be useful if you want to filter the Power Apps Gallery by the next or upcoming year.
- As today’s date is “8/22/2023“, the below Power Apps gallery displays all the records of the next year, i.e., 2024.
- To work with this, apply the code below on the gallery’s Items property:
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
)
)
Where,
- ‘IT Help Desk‘ = SharePoint List Name
- ‘Request Date‘ = SharePoint Date Column
- FirstDate, LastDate = Scope variable Names
This is how to filter the Power Apps gallery by next year.
Power Apps Filter Gallery By Next N Years
We will see how to filter Power Apps Gallery in this scenario by the next N years.
- Since my current year is “2023“, the below Power Apps gallery filters and displays all the records of the upcoming two years [from the SharePoint List] i.e. 2024 and 2025.
- For this, set the Gallery’s Items property to the code below:
Items = With(
{
FirstDate: Date(
Year(Today()),
Month(Today()),
Day(Today())
),
LastDate: Date(
Year(Today()) + 2, // Specify this number
Month(Today()),
Day(Today())
) - 1
},
Filter(
'IT Help Desk',
'Request Date' >= FirstDate,
'Request Date' <= LastDate
)
)
Where,
- ‘IT Help Desk‘ = SharePoint List Name
- ‘Request Date‘ = SharePoint Date Column
- FirstDate, LastDate = Scope variable Names
- 2 = Specify the upcoming year numbers
This is how to work with Power Apps Filter Gallery By Next N Years.
Also, you may like some more Power Apps tutorials:
- Power Apps Filter Gallery By Quarter [With Various Scenarios]
- Power Apps Filter Gallery By Last Week [With Various Scenarios]
- Power Apps Filter Gallery By Last Month [With Various Examples]
- Power Apps Filter Gallery By Date [With Examples]
- Power Apps Gallery Conditional Formatting [With 11 Examples]
- Power Apps Sequence Function [With Various Examples]
This Power Apps tutorial covered how to use Power Apps Filter Gallery By Year in various situations.
Additionally, we discussed 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
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com