Forum Discussion
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.
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
- jdbuchanan71Super User
When you say last, how do you determine that? Is there a date/time field on the table?
- AndreiFlorianFrequent Visitor
Hi,
I do have a timestamp attached to the data, I have an example of the table below.
Timestamp battery 06/10/2019 20:42:06 0 06/10/2019 20:42:06 0 06/10/2019 20:42:06 0 06/10/2019 20:42:06 3.3 06/10/2019 20:42:06 3.3 06/10/2019 20:42:06 3.2 06/10/2019 20:42:06 3.1 Ultimately, I need to return the last value (3.1).
Andrei
- jdbuchanan71Super 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 )
- AndreiFlorianFrequent 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.
- AndreiFlorianFrequent Visitor
- jdbuchanan71Super 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.