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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.