Forum Discussion

AndreiFlorian's avatar
AndreiFlorian
Frequent Visitor
6 years ago
Solved

Find Latest Value from Array

Hi there,

I am aware that there are other threads to do with this issue and I have looked over them though I did not manage to make the project work. I have an array called batteryVoltage which stores battery voltage and I want to get the last value appended to this array to use on a card. What would be the easiest way to do this?

 

Andrei.

  • jdbuchanan71's avatar
    jdbuchanan71
    6 years ago

    Hmm, I am guessing that the last row of data doesn't have a reading.  Can you try changing the mesure to this?

    Last Battery =
    VAR _MaxTime =
        CALCULATE (
            MAX ( 'SensoEvents'[TimeStamp] ),
            KEEPFILTERS ( ALL ( 'SensoEvents'[TimeStamp] ) )
        )
    RETURN
        CALCULATE ( SUM ( 'SensoEvent'[Battery] ), 'SensoEvents'[TimeStamp] = _MaxTime )
    

    See if keeping the other filters lets us get a result.

18 Replies

    • AndreiFlorian's avatar
      AndreiFlorian
      Frequent Visitor

      Hi,

      I do have a timestamp attached to the data, I have an example of the table below.

       

      Timestampbattery
      06/10/2019 20:42:060
      06/10/2019 20:42:060
      06/10/2019 20:42:060
      06/10/2019 20:42:063.3
      06/10/2019 20:42:063.3
      06/10/2019 20:42:063.2
      06/10/2019 20:42:063.1

       

      Ultimately, I need to return the last value (3.1).

      Andrei

      • jdbuchanan71's avatar
        jdbuchanan71
        Super User

        All of those times are the same (20:42:06) but assuming they are not that way in your data it will be something like so:

        Last Battery = 
        VAR _MaxTime = 
        CALCULATE(
            MAX ( 'Table'[Timestamp] ),
            ALL ( 'Table'[Timestamp] )
        )
        RETURN
        CALCULATE(
            SUM ( 'Table'[battery] ),
            'Table'[Timestamp] = _MaxTime
        )

  • AndreiFlorian's avatar
    AndreiFlorian
    Frequent Visitor

    Thank you!

    My bad, I was not aware that 'Table' had to be replaced with the name of the dataset, I am getting (blank) as the value of the field though.

    Andrei.

      • jdbuchanan71's avatar
        jdbuchanan71
        Super User

        Hmm, I am guessing that the last row of data doesn't have a reading.  Can you try changing the mesure to this?

        Last Battery =
        VAR _MaxTime =
            CALCULATE (
                MAX ( 'SensoEvents'[TimeStamp] ),
                KEEPFILTERS ( ALL ( 'SensoEvents'[TimeStamp] ) )
            )
        RETURN
            CALCULATE ( SUM ( 'SensoEvent'[Battery] ), 'SensoEvents'[TimeStamp] = _MaxTime )
        

        See if keeping the other filters lets us get a result.