Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
I am having trouble getting a slicer that shows the current year and the option to select last year. So, now we live in 2025. I want it to default to 2025 and the option to choose to see data from year 2024 in the slicer.
I have applied a hierarchy in the slicer that consists of year and month.
However, my data consists of years from 1970 to 2030.
How can I best do this?
Solved! Go to Solution.
@Bertje123456 you can create a calculated column with this code:
YearLabel =
IF(
'Table'[Year] = YEAR(TODAY()),
"This Year",
FORMAT('Table'[Year], "YYYY")
)
Then you can sort this new column by your year column and use it. If you leave it on "This Year," it will default to the current year and show the other years in the filter menu. If you want to show only This Year and the previous year, modify the code with:
YearLabel =
VAR THISYEARRR = IF(
'Table'[Year] = YEAR(TODAY()),
"This Year",
FORMAT('Table'[Year], "YYYY")
)
RETURN IF('Table'[Year] = YEAR(TODAY()) || 'Table'[Year] = YEAR(TODAY()) -1, THISYEARRR, BLANK())
If it's ok, please accept my answer as solution!
BBF
HI @Bertje123456 ,
First, use the following expression to create a table with a year slicer
Then I created a measure using the following expression
Cure and prev year =
var currentyear_ = SELECTEDVALUE(year_slicer[Year])
RETURN
IF(SELECTEDVALUE('Calendar 2'[DateKey].[Year])<= currentyear_ && SELECTEDVALUE('Calendar 2'[DateKey].[Year]) >= currentyear_ - 1,1,0)
Use this metric in the Filter panel and set it to 1
and use the table year_slicer to slicer fields
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Bertje123456 you can create a calculated column with this code:
YearLabel =
IF(
'Table'[Year] = YEAR(TODAY()),
"This Year",
FORMAT('Table'[Year], "YYYY")
)
Then you can sort this new column by your year column and use it. If you leave it on "This Year," it will default to the current year and show the other years in the filter menu. If you want to show only This Year and the previous year, modify the code with:
YearLabel =
VAR THISYEARRR = IF(
'Table'[Year] = YEAR(TODAY()),
"This Year",
FORMAT('Table'[Year], "YYYY")
)
RETURN IF('Table'[Year] = YEAR(TODAY()) || 'Table'[Year] = YEAR(TODAY()) -1, THISYEARRR, BLANK())
If it's ok, please accept my answer as solution!
BBF
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 14 | |
| 7 | |
| 4 | |
| 4 | |
| 3 |
| User | Count |
|---|---|
| 23 | |
| 10 | |
| 10 | |
| 6 | |
| 5 |