Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Calculate difference between values per category at irregularly spaced dates

Hi PowerBi Community, Background: I'm just learning PowerBI (it's a great tool!) and hoping you all can help me. I have found posts on the form about regularly spaced time interval comparisons (YoY,...
  • v-lid-msft's avatar
    6 years ago

    Hi Anonymous ,

     

    We can create measure use following formula to meet your requirement:

     

    LastChange = 
    VAR LastDay =
        MAX ( 'Table'[Date] )
    VAR LastTwoday =
        CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( 'Table', [Date] < LastDay ) )
    RETURN
        CALCULATE (
            SUM ( 'Table'[MyValue] ),
            FILTER ( 'Table', 'Table'[Date] = LastDay )
        )
            - CALCULATE (
                SUM ( 'Table'[MyValue] ),
                FILTER ( 'Table', 'Table'[Date] = LastTwoday )
            )

    If use your index column, this formula can be more easier:

     

    LastChangeUseIndex = 
    CALCULATE (
        SUM ( 'Table'[MyValue] ),
        FILTER ( 'Table', 'Table'[IndexCategory] = MAX ( 'Table'[IndexCategory] ) )
    )
        - CALCULATE (
            SUM ( 'Table'[MyValue] ),
            FILTER ( 'Table', 'Table'[IndexCategory] = MAX ( 'Table'[IndexCategory] ) - 1 )
        )

     


    BTW, pbix as attached.

     

    Best regards,

    Community Support Team _ Dong Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.