Forum Discussion

MarshalSK's avatar
MarshalSK
Resolver I
2 years ago
Solved

Calculating the difference dynamically, based on Year selection

Hi Folks, I need asssitance to acheieve below scenario.   Trying to calculate the sales difference for year on year and for each product. By default, all years will be dispayed, the main cache is i...
  • Jihwan_Kim's avatar
    2 years ago

    Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

    Please check the below picture and the attached pbix file.

    I hope the below can provide some ideas on how to create a solution for your semantic model.

     

     

     

     

    compare to the previous within the slicer selection: = 
    VAR _currentselectsales =
        SUM ( Sales[Sales] )
    VAR _currentselectyear =
        MAX ( 'Year'[Year] )
    VAR _prevselectyear =
        MAXX (
            FILTER ( ALLSELECTED ( 'Year' ), 'Year'[Year] < _currentselectyear ),
            'Year'[Year]
        )
    VAR _prevselectsales =
        CALCULATE ( SUM ( Sales[Sales] ), 'Year'[Year] = _prevselectyear )
    RETURN
        IF ( NOT ISBLANK ( _prevselectsales ), _currentselectsales - _prevselectsales )

     

  • MarshalSK's avatar
    MarshalSK
    2 years ago

    Perfect