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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Sanskruti
Helper II
Helper II

Custom year slicer

Hello,
I have a year slicer in which there are 4 years.

Sanskruti_0-1701411783418.png

For this current year i have used dax which is:

YearSlicer = if([Year]=year(today()),"Current Year",CONVERT([Year],STRING)).

But the requirement is instead of current year it should dispaly "2023" and by default the current year should be selected. 
And only last 4 years should be visible. For example: 
If the current year is 2024 the years visible should be:
2024, 2023, 2022 and 2021. 

Thank you in advance.

14 REPLIES 14
OwenAuger
Super User
Super User

Yes, as long as the dataset is refreshed so that Year Offset column = 0 for the current year.

 

The slicer selection is actually Year Offset = 0. It just displays the appropriate year as a label in place of 0, and the label will update to whichever year corresponds Year Offset =0.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

okay. And is it possible if we do this in dropdown?
And in the year offset column we have defined the end date. Will it dynamically change if the year changes? 

Right now, dropdown is unfortunately not possible with this new Slicer visual. And the original Slicer has no option for displaying labels and hiding values 😞

 

Yes, the "Year Offset" column will dynamically change on refresh as long as it is defined in a calculated column or table relative to TODAY() (using DAX) or similarly in Power Query.

 

My example version was defined in a calculated table using the TODAY() function to determine the current year.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

What if i selected year in dropdown slicer and used year offset in filter?

Sanskruti_0-1701431146016.png

Will this work if the date got changed?

 

I don't quite follow - could you clarify what you mean by that?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
AliceW
Impactful Individual
Impactful Individual

Why don't you just select the current year in the default published report? And set a hidden page filter with the last three years plus the current one? 

And just change this setting once per year, on January 1st?

thanks for replying @AliceW ,
We tried this method but this will not be a good practice.

Arul
Super User
Super User

@Sanskruti ,

You don't have direct option to do that. If you need some workaround may be you can try the approach mentioned in below thread,
https://community.fabric.microsoft.com/t5/Desktop/Set-default-value-of-current-year-in-slicer/td-p/2...





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Thank for replying @Arul ,
will look into it.

Anonymous
Not applicable

ok

OwenAuger
Super User
Super User

Hi @Sanskruti 

You can try the Preselected Slicer custom visual, assuming you are happy with the visual's appearance.

(Similar functionality should be coming to the core slicer visual at some stage but not yet.)

 

The sample workbook provided by the developer for this particular visual contains instructions, but I have attached a small example similar to what you have described, using a 'Date' table.

 

Components of this example:

1. A measure Current Year Flag, used in the Pre Selection field of the visual:

Current Year Flag = 
MAX ( 'Date'[Year] ) = YEAR ( TODAY () )

2. A measure Last 4 Years Flag used as a visual-level filter:

Last 4 Years Flag = 
VAR MaxYear = MAX ( 'Date'[Year] )
VAR CurrentYear =
    YEAR ( TODAY () )
RETURN
    INT (
        AND (
            MaxYear <= CurrentYear,
            MaxYear >= CurrentYear - 3
        )
    )

3. Once the visual is set up it looks like this:

OwenAuger_0-1701416147389.png

 

When the report page is opened, the current year will be selected (as long as it exists in the table).

 

Does this work for you?

 

Regards

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Hello @OwenAuger ,
Thanks for replying but we dont want to use custom visuals.
Thank you.

Understood 🙂
Would you be willing to use the "Slicer (new)" visual?

It would require the items to appear as buttons.

 

If you have a "Year Offset" column, you could place a "Year Offset" field on the slicer, filtered to zero (i.e. current year)

Then switch off Values (-3, -2, -1, 0) and instead show a Label defined by a measure returning the year (2020, 2021, 2022, 2023).

 

OwenAuger_0-1701422273197.png

Example attached.

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

This works @OwenAuger ,
But will the current year be selected by default?
Like when the year get 2024 the slicer should display and get selected as 2024.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

Top Solution Authors