Forum Discussion

dkushner's avatar
dkushner
Frequent Visitor
8 years ago
Solved

calculating difference with the previous value

Hello everybody, I need to find the difference between two rows within a table of values. I have a table like ID CounterNumber DateT SummAPlus 4598661 1 2018-01-25 13:00:00.000 1028987...
  • zvm's avatar
    zvm
    8 years ago

    Great!

    Just added MinDate to have 0 in a first row per CounterNumber.

    Column = 
    VAR CurrentDate = PowerCountersHours[DateT]
    VAR PreviousDate =
        CALCULATE (
            MAX ( PowerCountersHours[DateT] );
            FILTER (
                ALLEXCEPT ( PowerCountersHours; PowerCountersHours[CounterNumber] );
                PowerCountersHours[DateT] < CurrentDate
            )
        )
    VAR MinDate = 
        CALCULATE (
            MIN( PowerCountersHours[DateT] );
                 ALLEXCEPT ( PowerCountersHours; PowerCountersHours[CounterNumber] )
              )
    VAR PreviousValue = IF(PowerCountersHours[DateT] = MinDate; 
        CALCULATE (
            SUM ( PowerCountersHours[SummAPlus] );
            FILTER (
                ALLEXCEPT ( PowerCountersHours; PowerCountersHours[CounterNumber] );
                PowerCountersHours[DateT] = MinDate )
            ); 
        CALCULATE (
            SUM ( PowerCountersHours[SummAPlus] );
            FILTER (
                ALLEXCEPT ( PowerCountersHours; PowerCountersHours[CounterNumber] );
                PowerCountersHours[DateT] = PreviousDate
            )
        )
    )
    RETURN
        PowerCountersHours[SummAPlus] - PreviousValue