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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
JothiG
Helper III
Helper III

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
Super User
Super User

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 III
Helper III

It is working fine. thank you very much.

DanieleUgoCopp
Super User
Super User

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
Super User
Super User

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.