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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
MSchultz93
Frequent Visitor

Current Year and Current month in a slicer

Hello,

 

I have a problem with selections in a slicer. 

 

In my slicer I have the column calendar[Year], it contains 2021,2022,2023,2024,2025,2026. I want the current year to be selected, however, all years should be visible in the slicer.

 

The problem is when I create a calculated column where IsCurrentYear = if(Max(calendar[Year])=Year(Today()),1,0) and I select IsCurrentYear = 1 as a filter in the slicer only the current year appears. I want the current year to be selected but all others should appear.

 

Thank you for the help

 

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @MSchultz93 ,

 

You cannot have the selection of the current year based on a filter since it will only return the selected value.


The pre-selected value of a slicer can only be done by selecting the value and when you publish it that will be the default selection, or using a bookmark that will force that specific slicer to select the current year. however in both case if the year changes you need to go back and change it to the new year.

 

For this default selection of current year I usually create a column with the text Current Year and the rest of the years as numbers then I place the default value for that current year on the slicer so when the year changes the default selectionn get updated.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
shafiz_p
Super User
Super User

Hi @MSchultz93 To accomplish this create a year table with all distinct year values in power query. Sort year in ascending order. Create an index column from 0.  Create a currentYear custom column using the formula shown in the image below.

shafiz_p_1-1728552384304.png

 

 

Now recalculate Index column using the formula shown in the below:

shafiz_p_2-1728552472649.png

 

Now change type of sort index to whole number and CurrentYear to text. Remove Index column. See Image:

shafiz_p_3-1728552536719.png

Load data to power bi. Create on to many relationship using year column of the above table to calendar table year column.

 

shafiz_p_7-1728552902740.png


Now sort the newly created Current Year column by sort index column. See image below:

shafiz_p_4-1728552703070.png

 

Go to report page, create slicer and place the newly created current year column in values section. See image below:

shafiz_p_5-1728552828716.png

 

 

Hope this helps!!

If this solved your problem, Please accept it as a solution!!

 

 

Best Regards,
Shahariar Hafiz

MAwwad
Solution Sage
Solution Sage

  1. Create the Measure:

    IsCurrentYear = IF(YEAR(TODAY()) = MAX('Calendar'[Year]), 1, 0)
  2. Add the Slicer:

    • Add a slicer to your report and use the Calendar[Year] column.
    • Create the Bookmark:

      • Select the current year in the slicer.
      • Go to the View tab and open the Bookmarks pane.
      • Add a new bookmark and name it "Default Year".
      • Ensure that the bookmark captures the slicer state by checking the "Data" option in the bookmark settings.
      • Add the Button:

        • Insert a button into your report.
        • Go to the Action properties of the button.
        • Set the action type to Bookmark.
        • Select the "Default Year" bookmark.
MFelix
Super User
Super User

Hi @MSchultz93 ,

 

You cannot have the selection of the current year based on a filter since it will only return the selected value.


The pre-selected value of a slicer can only be done by selecting the value and when you publish it that will be the default selection, or using a bookmark that will force that specific slicer to select the current year. however in both case if the year changes you need to go back and change it to the new year.

 

For this default selection of current year I usually create a column with the text Current Year and the rest of the years as numbers then I place the default value for that current year on the slicer so when the year changes the default selectionn get updated.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.