Forum Discussion

JothiG's avatar
JothiG
Helper III
7 months ago
Solved

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

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

 

 

 

  • 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.

  • JothiG's avatar
    JothiG
    7 months ago

    i tried with this,

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

5 Replies

  • 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.

    • JothiG's avatar
      JothiG
      Helper III

      i tried with this,

      REMOVEFILTERS(Inventory_stock_dtl[Stock_fin_year])  still it is not working.
      • JothiG's avatar
        JothiG
        Helper III

        It is working perfectly. thank you very much.

  • 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.