Forum Discussion
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 https://1drv.ms/u/c/cfada767f73d87ed/EZUAXlsrP7NGqH_K6Ks647wB-kr-1Wq1kk9O6Ph-tXUHSA?e=inIHSg
Please advise!
Thanks in advance!
2 Replies
- WyattCrosbyIron Contributor
To test this DAX measure, you can create a card or a text box in your report and display the HeatingStatus measure. Make sure to configure the visual so it refreshes based on the current context.
- CyrusGroveIron Contributor
You can add the measure TotalSalesLast4Hours directly to a card visual to see the total sales amount in the last four hours. For product names, you may want to use a table visual to display the results of ProductsLast4Hours, although you would typically use this measure in a visual context.