I have a table including the column "time", "sensor_id" and "temperature". Every row in the table consist of a unique combination of time and sensor_id, but both columns have repeating values. I want to make a new column showing the time difference between the row's time and the time of the sensor's maximum temperature. However, I do not manage to do this seperately for every sensor. Instead, I only use the time of the maximum temperature overall- neglecting sensor_id. The code:
-----------------------------------------------------------
CloseToPeakTemp =
Var timeofMaxTemperature=CALCULATE(FIRSTNONBLANK(NeuronData[time_observed],true),
Filter(NeuronData,NeuronData[sensor_id]=SELECTEDVALUE(NeuronData[sensor_id])),
FILTER(NeuronData,MAX(NeuronData[WireTemperature])=NeuronData[WireTemperature]))
Var timeFromMaxTemp=ABS(NeuronData[time_observed]-timeofmaxTemperature)
return if(timeFromMaxTemp<TIMEVALUE("00:05"),TRUE,FALSE)
-----------------------------------------------------------
I know that the max function here, in the second Filter function, calculates the maximum temperature of all the measurements. I therefore want to change this to the maximum value for the row's sensor. SELECTED value is just an attempt to filter for the current row's sensor, but this won't be helpful without the sensor's maximum temperature as well. As the code is now, only the sensor with the maximum temperature will have correct values (assuming SelectedValue actually works). The other sensor's will just display the time differance between their row's time and the time of the other sensor's maximum temperature, which is useless information. To solve the problem using the current code, I would need to filter for the current row's sensor_id before finding the maximum- is that possible?
Alternatively, does anyone have another way of solving this problem? I have tried the GroupBy function to find the max temperatures, but I never managed to utilize the resulting table variable.