I'm fairly new to DAX & PowerBI and I'm trying to wrap my head around how I can determine and calculate timeframes per day.
The Goal:
- Get the minimum and maximum timestamps for each day in the data set
- Calculate the time difference between the two in HH:MM
- Created a calculated column to store the HH:MM result
So far I have found the following two DAX queries to work when creating a calculated column of the min and max timestamps:
CALCULATE(MIN('Packing Jobs - Pick Lines'[Timestamp]),FILTER('Packing Jobs - Pick Lines',FORMAT([Timestamp],"DD-MM-YYYY")=FORMAT(EARLIER([Timestamp]),"DD-MM-YYYY")))
CALCULATE(MAX('Packing Jobs - Pick Lines'[Timestamp]),FILTER('Packing Jobs - Pick Lines',FORMAT([Timestamp],"DD-MM-YYYY")=FORMAT(EARLIER([Timestamp]),"DD-MM-YYYY")))
However I am having a hard time trying to calculate and store the difference between the two results. I do not seem to be able to call the calculated columns when creating a new column to calculate, and when I have tried to combine them into the same column creation, the results are far from accurate.
Column =
VAR firstscan =
CALCULATE(MIN('Packing Jobs - Pick Lines'[Timestamp]),FILTER('Packing Jobs - Pick Lines',FORMAT([Timestamp],"DD-MM-YYYY HH:MM")=FORMAT(EARLIER([Timestamp]),"DD-MM-YYYY HH:MM")))
VAR lastscan =
CALCULATE(MAX('Packing Jobs - Pick Lines'[Timestamp]),FILTER('Packing Jobs - Pick Lines',FORMAT([Timestamp],"DD-MM-YYYY HH:MM")=FORMAT(EARLIER([Timestamp]),"DD-MM-YYYY HH:MM")))
RETURN
CALCULATE(lastscan - firstscan)
I have tried with and without and HH:MM
and the result still shows me in 1899 for every line. Any advice or pointers would be amazing!