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
JothiG
Helper II
Helper II

Need help -DAX(tooltipscreen)

9_1_difference =
VAR MaxYear = max(Inventory_stock_dtl[Stock_fin_year])
var _month_max = CALCULATE(MAX(Inventory_stock_dtl[month_sorter]), FILTER(all(Inventory_stock_dtl),
Inventory_stock_dtl[Stock_fin_year] = MaxYear))

var _month= SELECTEDVALUE(Inventory_stock_dtl[month_sorter])

var _month_calc = if (ISBLANK(_month),_month_max,_month)


var cur_mon_val = CALCULATE(
SUM(Inventory_stock_dtl[value]),
Inventory_stock_dtl[Stock_fin_year] = MaxYear &&
Inventory_stock_dtl[month_sorter] =_month_calc --,
-- ALLEXCEPT(Inventory_stock_dtl,Inventory_stock_dtl[Item])

)
var prev_mon_val = CALCULATE(
SUM(Inventory_stock_dtl[value]),
Inventory_stock_dtl[Stock_fin_year] = MaxYear-1 &&
Inventory_stock_dtl[month_sorter] =_month_calc --,
-- ALLEXCEPT(Inventory_stock_dtl,Inventory_stock_dtl[Item])

)

return
if(prev_mon_val <> 0 ,cur_mon_val-prev_mon_val )

---------------------------------------------------------

this is my tooltip screen dax for finding value difference between selected year month value and previous year month value.
This is perfectly working i did not filter the year .sample screen attached

JothiG_1-1767007646150.png

if i filter the year ,previous year value is not showing

JothiG_2-1767007763950.png

 

 

 

2 ACCEPTED SOLUTIONS
burakkaragoz
Community Champion
Community Champion

Hi @JothiG ,

The issue you are facing is due to Filter Context.

When you select "2025" in your slicer (as shown in your screenshot), Power BI filters the entire data model to only show rows where Stock_fin_year = 2025. Consequently, when your measure tries to calculate prev_mon_val for 2024, it returns BLANK/Zero because 2024 data has been filtered out by that slicer.

To fix this, you must tell DAX to ignore the filter on the Stock_fin_year column specifically for the previous year calculation.

Here is the corrected DAX:

9_1_difference = 
VAR MaxYear = MAX(Inventory_stock_dtl[Stock_fin_year])
VAR _month_max = 
    CALCULATE(
        MAX(Inventory_stock_dtl[month_sorter]), 
        FILTER(ALL(Inventory_stock_dtl), Inventory_stock_dtl[Stock_fin_year] = MaxYear)
    )
VAR _month = SELECTEDVALUE(Inventory_stock_dtl[month_sorter])
VAR _month_calc = IF(ISBLANK(_month), _month_max, _month)

VAR cur_mon_val = 
    CALCULATE(
        SUM(Inventory_stock_dtl[value]),
        Inventory_stock_dtl[Stock_fin_year] = MaxYear,
        Inventory_stock_dtl[month_sorter] = _month_calc
    )

VAR prev_mon_val = 
    CALCULATE(
        SUM(Inventory_stock_dtl[value]),
        Inventory_stock_dtl[Stock_fin_year] = MaxYear - 1,
        Inventory_stock_dtl[month_sorter] = _month_calc,
        -- The Fix: Remove the filter on the Year column to allow access to data from previous years
        REMOVEFILTERS(Inventory_stock_dtl[Stock_fin_year]) 
    )

RETURN
    IF(prev_mon_val <> 0, cur_mon_val - prev_mon_val)

What changed? I added REMOVEFILTERS(Inventory_stock_dtl[Stock_fin_year]) inside the prev_mon_val calculation.

  • This allows the measure to "see" 2024 data even though the slicer is set to 2025.

  • It keeps all other filters (like Item Category or Division) intact, so your comparisons remain accurate.

Hope this helps you get the correct variance!


If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
This response was assisted by AI for translation and formatting purposes.

View solution in original post

i tried with this,

REMOVEFILTERS(Inventory_stock_dtl[Stock_fin_year])  still it is not working.

View solution in original post

5 REPLIES 5
JothiG
Helper II
Helper II

It is working fine. thank you very much.

DanieleUgoCopp
Resolver I
Resolver I

Try to ignore the year filter only for the previous year calculation.
Wrap the previous year CALCULATE with ALL on the year column, so the measure can still access last year even when a year slicer is applied.

burakkaragoz
Community Champion
Community Champion

Hi @JothiG ,

The issue you are facing is due to Filter Context.

When you select "2025" in your slicer (as shown in your screenshot), Power BI filters the entire data model to only show rows where Stock_fin_year = 2025. Consequently, when your measure tries to calculate prev_mon_val for 2024, it returns BLANK/Zero because 2024 data has been filtered out by that slicer.

To fix this, you must tell DAX to ignore the filter on the Stock_fin_year column specifically for the previous year calculation.

Here is the corrected DAX:

9_1_difference = 
VAR MaxYear = MAX(Inventory_stock_dtl[Stock_fin_year])
VAR _month_max = 
    CALCULATE(
        MAX(Inventory_stock_dtl[month_sorter]), 
        FILTER(ALL(Inventory_stock_dtl), Inventory_stock_dtl[Stock_fin_year] = MaxYear)
    )
VAR _month = SELECTEDVALUE(Inventory_stock_dtl[month_sorter])
VAR _month_calc = IF(ISBLANK(_month), _month_max, _month)

VAR cur_mon_val = 
    CALCULATE(
        SUM(Inventory_stock_dtl[value]),
        Inventory_stock_dtl[Stock_fin_year] = MaxYear,
        Inventory_stock_dtl[month_sorter] = _month_calc
    )

VAR prev_mon_val = 
    CALCULATE(
        SUM(Inventory_stock_dtl[value]),
        Inventory_stock_dtl[Stock_fin_year] = MaxYear - 1,
        Inventory_stock_dtl[month_sorter] = _month_calc,
        -- The Fix: Remove the filter on the Year column to allow access to data from previous years
        REMOVEFILTERS(Inventory_stock_dtl[Stock_fin_year]) 
    )

RETURN
    IF(prev_mon_val <> 0, cur_mon_val - prev_mon_val)

What changed? I added REMOVEFILTERS(Inventory_stock_dtl[Stock_fin_year]) inside the prev_mon_val calculation.

  • This allows the measure to "see" 2024 data even though the slicer is set to 2025.

  • It keeps all other filters (like Item Category or Division) intact, so your comparisons remain accurate.

Hope this helps you get the correct variance!


If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
This response was assisted by AI for translation and formatting purposes.

i tried with this,

REMOVEFILTERS(Inventory_stock_dtl[Stock_fin_year])  still it is not working.

It is working perfectly. thank you very much.

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.