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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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