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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
sid_5005
Frequent Visitor

Bar chart should show current year data when no value is selected in year slicer

Hi All,
I have a year slicer and the functionality that I am trying to achieve is the Bar chart should show current year data when no value is selected in year slicer. For this i created a measure as per the post below but its not working 
https://community.fabric.microsoft.com/t5/Desktop/Show-current-year-data-if-no-filter-is-selected/td... 
Below is the code for the measure that I have created :
Measure = 

var selected_year = IF(ISFILTERED('Calendar'[Date]),SELECTEDVALUE('Calendar'[Date].[Year]),YEAR(TODAY()))
return
IF(SELECTEDVALUE('Calendar'[Date].[Year])=selected_year,1,0)
As  directed in the post when I apply this filter I am able to filter the bar chart to current year when no year is selected in the slicer but when I select a previous year I do not see the data for that year. Below are the screen shots :
sid_5005_1-1705595065276.pngsid_5005_2-1705595115571.png

Is there any other way to achieve this or does the DAX code needs to be tweaked ?
Thank you and Regards


 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @sid_5005 

May I ask if this is the expected output you are looking for? Based on your description, I have created many measures to achieve the effect you are looking for. Following picture shows the effect of the display.

vyaningymsft_2-1705631221758.png

 

vyaningymsft_3-1705631235591.png

Measures:

AppearDataByYear =

VAR _slicer_count =

    DISTINCTCOUNT ( 'Slicer'[Year] ) //Get all rows in the 'Slicer'[Year] column

VAR _all_count =

    COUNTROWS ( ALL ( 'Slicer' ) ) //Ignore the filtering of the Slicer table and calculate the number of rows in the Slicer table

VAR _selcet_years =

    ALLSELECTED ( 'Slicer'[Year] ) //Get the year filtered in the slicer

VAR _max_year =

    CALCULATE ( MAX ( 'Table'[Year] ), ALL () ) //Get the maximum value of the year in the 'Table'[Year] column, 2023

VAR _filter =

    SWITCH (

        TRUE (),

        _slicer_count = _all_count, IF ( SELECTEDVALUE ( 'Table'[Year] ) = _max_year, 1 ),

        //The slicer is not filtered, if the value in the 'Table'[Year] column is equal to 2023, give a status 1

        _slicer_count < _all_count,

            IF ( SELECTEDVALUE ( 'Table'[Year] ) IN _selcet_years, 1 ) //The slicer is partially filtered, if the range of values in column 'Table'[Year] is in _selcet_years, give a status 1

    )

RETURN

    _filter

 

If this does not work, could you please share some sample data without sensitive information and expected output.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi, @sid_5005 

May I ask if this is the expected output you are looking for? Based on your description, I have created many measures to achieve the effect you are looking for. Following picture shows the effect of the display.

vyaningymsft_2-1705631221758.png

 

vyaningymsft_3-1705631235591.png

Measures:

AppearDataByYear =

VAR _slicer_count =

    DISTINCTCOUNT ( 'Slicer'[Year] ) //Get all rows in the 'Slicer'[Year] column

VAR _all_count =

    COUNTROWS ( ALL ( 'Slicer' ) ) //Ignore the filtering of the Slicer table and calculate the number of rows in the Slicer table

VAR _selcet_years =

    ALLSELECTED ( 'Slicer'[Year] ) //Get the year filtered in the slicer

VAR _max_year =

    CALCULATE ( MAX ( 'Table'[Year] ), ALL () ) //Get the maximum value of the year in the 'Table'[Year] column, 2023

VAR _filter =

    SWITCH (

        TRUE (),

        _slicer_count = _all_count, IF ( SELECTEDVALUE ( 'Table'[Year] ) = _max_year, 1 ),

        //The slicer is not filtered, if the value in the 'Table'[Year] column is equal to 2023, give a status 1

        _slicer_count < _all_count,

            IF ( SELECTEDVALUE ( 'Table'[Year] ) IN _selcet_years, 1 ) //The slicer is partially filtered, if the range of values in column 'Table'[Year] is in _selcet_years, give a status 1

    )

RETURN

    _filter

 

If this does not work, could you please share some sample data without sensitive information and expected output.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Thank you for this.🙂

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Solution Authors
Top Kudoed Authors