Forum Discussion

PSRai's avatar
PSRai
Helper III
6 years ago

HELP

Hi, 

I need to create an Output column as below.

I have one column that reads [energy] data per socket across multiple sockets per by seconds. the energy reading per [socket_id] will increase unless the socket is switched off which then energy will be ZERO. when the socket is switched back on the energy readings will start increasing again from ZERO upwards. What I need to do is, when the socket is switched off and back on apply the last MAX energy reading before Switch off (per socket) and apply the reading to all new readings. Before the Socket is switched off the Energy column and Output column should be the same (as below). I only have one table with all columns

 

read_at                            socket_id             Energy                   Output

18/10/2019 13:01:01       1                              0.10                        0.10

18/10/2019 13:01:05       1                              0.30                        0.30

18/10/2019 13:01:07       1                              0.50                        0.50

18/10/2019 13:01:09       1                              0.60                        0.60

18/10/2019 13:01:11       1                              1.00                        1.00

18/10/2019 13:01:15       1                              0.00                        1.00

18/10/2019 13:01:18       1                              0.30                        1.30

18/10/2019 13:01:20       1                              0.50                        1.50

18/10/2019 13:01:22       1                              0.70                        1.70

18/10/2019 13:01:25       1                              0.00                        1.00

18/10/2019 13:01:26       1                              0.20                        1.20

 

I have been given the following code

  Output =

VAR maxenerge =

    CALCULATE ( MAX ( 'readings'[Energy] ), ALLEXCEPT ( 'readings', 'readings'[socket_id] ) )

RETURN

         IF (

        'readings'[read_at]

            <= CALCULATE (

                LOOKUPVALUE ( 'readings'[read_at], 'readings'[Energy], maxenerge ),

                ALLEXCEPT ( 'readings', 'readings'[socket_id )

            ),

        'readings'[Energy],

        maxenerge + 'readings'[Energy]

    )

Can someone urgently help please?

 

 

however, get the following error. 

"A table of multiple values was supplied where a single value was expected"

12 Replies

  • Mariusz's avatar
    Mariusz
    Community Champion

    HI PSRai 

     

    Please see the attached file with the solution.

    If you have any questions please let me know.

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    Mariusz Repczynski

     

    • PSRai's avatar
      PSRai
      Helper III

      Mariusz Thank you that's exactly what i'm looking for,

       

      Can you provide the syntax please of how you created the output column?

  • Hi,

    Shouldn't the result in the last 2 rows of the output column be 1.7 and 1.9?