Create a dax to filter only last four hours and lookup a column
Hi Team,
I have below sample data:
We need to create a dax using below logics:
filter HeatSense_Device table for last four hours(use ‘UpdatedOn'(max&min datetime) column for this)Then look if the ‘UserMode’ contains ‘heat’ in all rows.If the above 2 conditions are true then return “Heating on Last 4 Hours” else blank.
We tried to create the below logic but its not giving correct output:
Last 4 Hours in Heat =
var latestdatetime = max(HeatSense_Device[UpdatedOn])
var earliestdatetime = latestdatetime-4/24
var last4hours =
CALCULATETABLE(HeatSense_Device,HeatSense_Device[UpdatedOn]<=latestdatetime && HeatSense_Device[UpdatedOn]>=earliestdatetime)
var maximummode = MAXX(last4hours,HeatSense_Device[UserMode])
var minimummode = MINX(last4hours,HeatSense_Device[UserMode])
return
if(and(maximummode=”heat”,minimummode=”heat”),”Heating on Last 4 Hours”,BLANK())
Ouput:
When I bring in UpdatedOn column into visual to test the above dax, it retuns the whole 24hours instead of last four hours. I want to show only last four hours where there is heat in table.
Could you please help us in creating a dax or modify the above dax ?
PFA file here Heatsense – Copy.pbix
Please advise!
Thanks in advance!
Hi Team, I have below sample data: We need to create a dax using below logics:filter HeatSense_Device table for last four hours(use ‘UpdatedOn'(max&min datetime) column for this)Then look if the ‘UserMode’ contains ‘heat’ in all rows.If the above 2 conditions are true then return “Heating on Last 4 Hours” else blank.We tried to create the below logic but its not giving correct output: Last 4 Hours in Heat =
var latestdatetime = max(HeatSense_Device[UpdatedOn])
var earliestdatetime = latestdatetime-4/24
var last4hours =
CALCULATETABLE(HeatSense_Device,HeatSense_Device[UpdatedOn]<=latestdatetime && HeatSense_Device[UpdatedOn]>=earliestdatetime)
var maximummode = MAXX(last4hours,HeatSense_Device[UserMode])
var minimummode = MINX(last4hours,HeatSense_Device[UserMode])
return
if(and(maximummode=”heat”,minimummode=”heat”),”Heating on Last 4 Hours”,BLANK()) Ouput: When I bring in UpdatedOn column into visual to test the above dax, it retuns the whole 24hours instead of last four hours. I want to show only last four hours where there is heat in table.Could you please help us in creating a dax or modify the above dax ? PFA file here Heatsense – Copy.pbixPlease advise! Thanks in advance!@SergeiBaklan Read More