skh
skh

Reputation: 27

Show latest value based on value in another column - Power BI

I have some sensordata that i would like to visualize. I would like to show the latest value based on the sensor type, for example "openings" (picture bleow). The openings sensor counts how many times a door has been opened and therefore the value can change quite often. I would like to show the latest value and i will also do this with the other sensortypes.  For example to show the latest temperature as a card visualization.

I have noe been able to do it. Have for example tried lastnonblank, but didnt work since i used two colums(value, sensortype).

Any suggestions on how i can solve this?

Thanks in advance! 

enter image description here

Upvotes: 0

Views: 2542

Answers (1)

Aldert
Aldert

Reputation: 4323

You can add a new column, based on sensortype and latest date value. First I filter the table based on SensorType. Thi I use to get teh last date and in the calculate I get the value related to this date. Please note, I did not test this with your example so might have a typo.

lastValue =
    var sensorType = MyTable[Sensor Type]
    var sensorTypeRows = FILTER(MyTable,MyTable[Sensor Type] = sensorType)
    var lastD = MAXX(sensorTypeRows, MyTable[TimeAndDate])
return CALCULATE(MAX(MyTable[value]), Filter(sensorTypeRows, lastD = MyTable[TimeAndDate]))

Upvotes: 1

Related Questions