Forum Discussion

scott_bab's avatar
scott_bab
Frequent Visitor
7 years ago
Solved

Calculate sales measure

I have an interesting scenario that I have not been able to crack thus far.   I have a slicer where I can select a particular store, and I want to be able to view the department sales for the selec...
  • Vvelarde's avatar
    7 years ago

    scott_bab 

     

    Hi, try with this measure:

     

    Measure =
    VAR _District =
        SELECTEDVALUE ( Sales[District] )
    VAR _Division =
        SELECTEDVALUE ( Sales[Division] )
    VAR _Context =
        SELECTEDVALUE ( Context[Context Name] )
    RETURN
        SWITCH (
            _Context;
            "Store"; SUM ( Sales[2018 Sales] );
            "District"; CALCULATE (
                SUM ( Sales[2018 Sales] );
                KEEPFILTERS ( VALUES ( Sales[Department] ) );
                FILTER ( ALL ( 'Sales' ); Sales[District] = _District )
            );
            "Division"; CALCULATE (
                SUM ( Sales[2018 Sales] );
                KEEPFILTERS ( VALUES ( Sales[Department] ) );
                FILTER ( ALL ( 'Sales' ); Sales[Division] = _Division )
            )
        )
    

    If doesn't work replace ; with ,

     

    Maybe need to optimize code but i think will work.

     

     

    PD. I forgot to tell you

     

    I create a disconnected table with a column named "Context  with this 3 rows : "Store", "District" and Division" and insert it in Columns section in Matrix)

     

    Regards

     

    Victor