Forum Discussion

George1973's avatar
George1973
Icon for Helper V rankHelper V
4 years ago
Solved

Difference between results based on slicer selection

Hi All, I have a column with all customers in it and a "Total Sales" measure. I want to calculate a difference between selected two companies total sales based on a slicer company selection. - I...
  • VahidDM's avatar
    4 years ago

    Hi George1973 

     

    You did not share a sample of data so I will explain my solution, then you can try it:

    1- When you select 2 Items with Slicer the your table will be filtered to show all data for those selected customers 
    2- You need to write a measure, so first add a VAR to create a table and add a rank column to it to rank rows based on the customers' names (ADDCOLUMN & RANKX), the output will be the filtered table with a column that has 1 and 2 (first customer and 2nd costumer)
    3- then add another VAR (Name it S1) to SUMX a sales when the RANK is 1 (Filter RANK =1)

    4- add another VAR to SUMX (Name it S2)a sale when the RANK is 2 (Filter RANK =1)

    5- at the end (RETURN) S2-S1

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/

     

     

  • George1973's avatar
    George1973
    4 years ago

    Hi,

     

    First of all, sorry for beeing late with the answer. I have write a measure according to your suggestion and it works fine.

    Variance from Selected Companies = 
    VAR summary =
        ADDCOLUMNS (ALLSELECTED(Item_Table[Company]), "cCompany", RANKX(ALLSELECTED(Item_Table[Company]),[Grand Total]))
    VAR S1=
        CALCULATE([Grand Total],FILTER(summary,[cCompany]=1))
    VAR S2=
        CALCULATE([Grand Total],FILTER(summary,[cCompany]=2))
    Return
    S1-S2

     

    Here is the result:

     

    Thank you very much for assistance.