Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Dynamically calculate differences based on slicer slection

Hello, I have a table with Revenues of all months and I need to build a difference between two selected months.
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

     

    Thanks for the reply from ahadkarimi , please allow me to provide another insight: 

     

    You can create measure.

    Diff = 
    VAR _min =
        CALCULATE ( MIN ( 'financials'[Date] ), ALLSELECTED ( financials[Date] ) )
    VAR _max =
        CALCULATE ( MAX ( 'financials'[Date] ), ALLSELECTED ( financials[Date] ) )
    VAR _s1 =
        CALCULATE ( SUM ( 'financials'[ Sales] ), 'financials'[Date] = _min )
    VAR _s2 =
        CALCULATE ( SUM ( financials[ Sales] ), 'financials'[Date] = _max )
    RETURN
        _s2 - _s1
    

     


    It is worth noting that if three and more dates are selected in the slicer, it still calculates the difference between the maximum and minimum dates.

     

    If your Current Period does not refer to this, please clarify in a follow-up reply.

     

    Best Regards,

    Clara Gong

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

     

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

     

    You can create measure.

    Revenue 1. month = 
    VAR _min =
        CALCULATE ( MIN ( 'Table'[Date] ), ALLSELECTED ( 'Table'[Date] ) )
    VAR _sum =
        CALCULATE ( SUM ( 'Table'[Revenue] ), 'Table'[Date] = _min )
    RETURN
        _sum
    

     

    Revenue 2. month = 
    VAR _max =
        CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table'[Date] ) )
    VAR _sum =
        CALCULATE ( SUM ( 'Table'[Revenue] ), 'Table'[Date] = _max )
    RETURN
        _sum
    

     

    Diff = 
    [Revenue 2. month] - [Revenue 1. month]

    If your Current Period does not refer to this, please clarify in a follow-up reply.

     

    Best Regards,

    Clara Gong

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.