Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Calculate difference between to rows in the same column

I am trying to calculate the variance of projects, over different periods. Periods are referenced as P1, P2,...

The user should be able to pick the periods that they want to compare and see the projects listed

 

PeriodObject       WIPIndexIndex.1
FY22 P01PRJ28,90601
FY22 P02PRJ3,90612
FY22 P01PRJ25,50601
FY22 P02PRJ28,00012

 

I have tried a dax formula, but I can't find one that has more than one filter.

 

My DAX:

Variance = VAR DIFF = WIP[ WIP]-

CALCULATE(sum(WIP[ WIP]), 

FILTER('WIP', WIP[Index1]=EARLIER(WIP[Index])))

return IF(DIFF=VALUE(WIP[ WIP]), 0,

DIFF

)

 

Can you help?

6 Replies

  • Hi Anonymous,

     

    What do you mean by "more than one filter?" Also, are you trying to get the difference between two succeeding periods for every object? If that is the case, try this formula as a calc column

    Diff = 
    VAR _prev =
        CALCULATE (
            SUM ( Data[WIP] ),
            FILTER (
                ALL ( Data ),
                Data[Index] < EARLIER ( Data[Index] )
                    && Data[Object] = EARLIER ( Data[Object] )
            )
        )
    RETURN
        Data[WIP] - _prev
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for this.

      Sorry but it didn't work.

      I'm not sure what is doing.

      An object where variance should be 0, shows different figures