Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Using DAX to make a column: how to filter using a value in the current row

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. 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Something like this

CloseToPeakTemp =
Var SID=SELECTEDVALUE(NeuronData[sensor_id])
Var timeofMaxTemperature=CALCULATE(FIRSTNONBLANK(NeuronData[time_observed],true),
Filter(NeuronData,NeuronData[sensor_id]=SID),
FILTER(NeuronData,MAX(NeuronData[WireTemperature])=NeuronData[WireTemperature]))
Var timeFromMaxTemp=ABS(NeuronData[time_observed]-timeofmaxTemperature)
return if(timeFromMaxTemp<TIMEVALUE("00:05"),TRUE,FALSE)

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

Something like this

CloseToPeakTemp =
Var SID=SELECTEDVALUE(NeuronData[sensor_id])
Var timeofMaxTemperature=CALCULATE(FIRSTNONBLANK(NeuronData[time_observed],true),
Filter(NeuronData,NeuronData[sensor_id]=SID),
FILTER(NeuronData,MAX(NeuronData[WireTemperature])=NeuronData[WireTemperature]))
Var timeFromMaxTemp=ABS(NeuronData[time_observed]-timeofmaxTemperature)
return if(timeFromMaxTemp<TIMEVALUE("00:05"),TRUE,FALSE)
lbendlin
Super User
Super User

you should not use SELECTEDVALUE() inside CALCULATE(). Use variables instead.

Anonymous
Not applicable

Ok, so how can I find the sensor_id for the row and use it as a variable? That would solve all my problems!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors