Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Bertje123456
Frequent Visitor

I want the slicer to show current year and one year before

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. 

 

Bertje123456_0-1737560706763.png

 

 

How can I best do this? 

1 ACCEPTED SOLUTION
BeaBF
Super User
Super User

@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

View solution in original post

2 REPLIES 2
vivek31
Resolver II
Resolver II

HI @Bertje123456 ,

First, use the following expression to create a table with a year slicer

vivek31_0-1737564259524.png

 

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

vivek31_2-1737564533212.png

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 



BeaBF
Super User
Super User

@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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.