Forum Discussion

flintstone's avatar
flintstone
Helper II
6 years ago

Convert cumulative data to non-comulative data

I have real time energy consumption data with a timestamp streaming from a websocket.

16/7/2020 00:00.00     6

16/7/2020 00:00.00     14

16/7/2020 00:00.00     17

16/7/2020 00:00.00     34

 

I would like to get Powerbi to show the non-cumulative values as show below in the lat column

16/7/2020 00:00.00     6        6

16/7/2020 00:00.00     14     8

16/7/2020 00:00.00     17     3

16/7/2020 00:00.00     34    17

 

Any help would be appreciated.

 

15 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    Assuming the time component of your DateTime values are not all zeros, you can use an expression like this to get your result in a measure.  Use the measure in a table visual with your DateTime column.  Let me know if you need the column version instead.

     

     

    Actual Consumption =
    VAR __thisvalue =
        MIN ( Table[EnergyConsumed] )
    VAR __thisdatetime =
        MIN ( Table[DateTime] )
    VAR __prevdatetime =
        CALCULATE (
            MAX ( Table[DateTime] ),
            ALL ( Table[DateTime] ),
            Table[DateTime] < __thisdatetime
        )
    VAR __prevvalue =
        CALCULATE (
            MIN ( Table[EnergyConsumed] ),
            ALL ( Table[DateTime] ),
            Table[DateTime] = __prevdatetime
        )
    RETURN
        __thisvalue - __prevvalue

     

     

    If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat

  • Hi,

    This calculated column formula works

    Column = Casting[Incoming 33kv]-LOOKUPVALUE(Casting[Incoming 33kv],Casting[DateTimeStamp],CALCULATE(MAX(Casting[DateTimeStamp]),FILTER(Casting,Casting[DateTimeStamp]<EARLIER(Casting[DateTimeStamp]))))

    Hope this helps.