Forum Discussion

Mattm1989's avatar
Mattm1989
Regular Visitor
1 year ago
Solved

Issue with variance calculations

Hi

 

Please could someone help me understand what I am doing wrong?

 

I am using variables to calculate the sum of the same column but using different selections based on a different column via slicers. I then want to find the difference between those 2 totals. See below:

The issue is the difference comes back as blank when 2 different options are selected from the slicer.

Currently here is my DAX:

 

Var01 =
VAR Actual_Bud_01 = SELECTEDVALUE(Master[Actual / Budget1])
VAR Total_Act_Bud_01 = CALCULATE(SUM(Master[Amt USD - PTD1]), Master[Actual / Budget1] = Actual_Bud_01)
RETURN Total_Act_Bud_01
Var02 =
VAR Actual_Bud_02 = SELECTEDVALUE(Master[Actual / Budget1])
VAR Total_Act_Bud_02 = CALCULATE(SUM(Master[Amt USD - PTD1]), Master[Actual / Budget1] = Actual_Bud_02)
RETURN Total_Act_Bud_02
 
Var_diff2 = [Var01] - [Var02]
 
I have edited interactions as such (opposite selection for the other slicer):

Also if the same selection is selected across both filters, the difference will return 0:

Thank you!



  • Hi Mattm1989 

    Unfortunately the slicers count as an AND filter on the card.

    Meaning it tries to filter your Master table to only rows that fufill BOTH criteria.

     

    You can either:

    Use one slicer and have the two measures return only one of the items in the list. If the user can only ever choose one using Min on one and max on the other would work. 

    Var01 =
    VAR Actual_Bud_01 = Max(Master[Actual / Budget1])
    VAR Total_Act_Bud_01 = CALCULATE(SUM(Master[Amt USD - PTD1]), Master[Actual / Budget1] = Actual_Bud_01)
    RETURN Total_Act_Bud_01
     
    Or you have a second copy of the Master[Actual/budget] column in a seperate and completely unlinked table for the second calculation.

     

    Var01 =
    VAR Actual_Bud_01 = SelectedValue(MasterCopy[Actual / Budget1])
    VAR Total_Act_Bud_01 = CALCULATE(SUM(Master[Amt USD - PTD1]), Master[Actual / Budget1] = Actual_Bud_01)
    RETURN Total_Act_Bud_01
     
     
    Let me know if you get stuck 🙂

2 Replies

  • Hi Mattm1989 

    Unfortunately the slicers count as an AND filter on the card.

    Meaning it tries to filter your Master table to only rows that fufill BOTH criteria.

     

    You can either:

    Use one slicer and have the two measures return only one of the items in the list. If the user can only ever choose one using Min on one and max on the other would work. 

    Var01 =
    VAR Actual_Bud_01 = Max(Master[Actual / Budget1])
    VAR Total_Act_Bud_01 = CALCULATE(SUM(Master[Amt USD - PTD1]), Master[Actual / Budget1] = Actual_Bud_01)
    RETURN Total_Act_Bud_01
     
    Or you have a second copy of the Master[Actual/budget] column in a seperate and completely unlinked table for the second calculation.

     

    Var01 =
    VAR Actual_Bud_01 = SelectedValue(MasterCopy[Actual / Budget1])
    VAR Total_Act_Bud_01 = CALCULATE(SUM(Master[Amt USD - PTD1]), Master[Actual / Budget1] = Actual_Bud_01)
    RETURN Total_Act_Bud_01
     
     
    Let me know if you get stuck 🙂
  • Mattm1989's avatar
    Mattm1989
    Regular Visitor

    Makes complete sense now! I've gone for a completely separate table on second calc and getting the result I require! thank you!