Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Measure does not show correct variance when pivot table filter context does not contain any value

Hello,

 

What I want to do:

Sort column C by the "difference from", "Scen2" column shown below in descending order. 

 

What I tried doing already:

1. Create a "Difference From" column from "Value Field Setting" and sort --> did not work

2. Create a measure to simulate "Difference From" through Power Query --> sorting seems to work but the columns are mixed as highlighted in yellow above.

 

DAX Formula:

 

 

 

=VAR sum_scen1 = CALCULATE(SUM(Table1[annual]), Table1[A]="Scen1")
VAR sum_scen2 = CALCULATE(SUM(Table1[annual]), Table1[A]="Scen2")
RETURN sum_scen2-sum_scen1

 

 

 

 

I wish there is a place to attach the file but here it is!

Thank you!

 

  • Hi Anonymous ,

     

    Please show grand totals in Excel. Does this match your desired output?

     

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks Ibendlin! This link should now work.

  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi Anonymous ,

     

    Please try the measure and change the subtotal label.

     

    Measure = 
    VAR sum_scen1 =
        CALCULATE ( SUM ( Table1[annual] ), Table1[A] = "Scen1" )
    VAR sum_scen2 =
        CALCULATE ( SUM ( Table1[annual] ), Table1[A] = "Scen2" )
    RETURN
        IF ( ISFILTERED ( Table1[A] ), SUM ( Table1[annual] ), sum_scen2 - sum_scen1 )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for your reply!

      However, this solution does not seem to work in Excel Power Query/Power Pivot.

      Would you please take a look at this again?

      Thanks!

       

       

      • v-kkf-msft's avatar
        v-kkf-msft
        Community Support

        Hi Anonymous ,

         

        Please show grand totals in Excel. Does this match your desired output?

         

         

        If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
        Best Regards,
        Winniz
        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.