Forum Discussion
Find Latest Value from Array
- 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.
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
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
)
- AndreiFlorian6 years agoFrequent Visitor
Hi, I tried the code provided but I get the following errors when hovering over the table names:
Parameter is not the correct type
Cannot find name '[Timestamp]'
Andrei.
- jdbuchanan716 years agoSuper User
Is the field called something else in your model or is it not a date/time field?
- AndreiFlorian6 years agoFrequent Visitor
The field names are correct, I am not sure if the timestamp field is classified as a time field. It seems to be the same as the battery field. Is there a way to declare it as a date/time field?
Andrei