Forum Discussion
shane7mcdonald
5 years agoFrequent Visitor
Calculating time difference before and after a specific time
Hi, I'm a bit stumped on this problem and was hoping for some help. I need to find the difference between the last date/time BEFORE 6am, and the first date/time AFTER 6am. I'm trying to find out ...
AlB
5 years agoCommunity Champion
Where do you want this, in a measure? If so:
Measure =
VAR date_ =
INT ( MAX ( Table1[DateTime] ) )
VAR lastBefore6_ =
CALCULATE (
MAX ( Table1[DateTime] ),
Table1[DateTime] < ( date_ + ( 6 / 24 ) )
)
VAR firstAfter6_ =
CALCULATE (
MIN ( Table1[DateTime] ),
Table1[DateTime] >= ( date_ + ( 6 / 24 ) )
)
VAR diffInMinutes_ = ( firstAfter6_ - lastBefore6_ ) * 24 * 60
RETURN
diffInMinutes_
Take into account though that the code above is tailored to the table you show. I guess you are looking for a more general result, like the average of that time difference across days, etc. You'll have to tweak it a bit for that, but the main logic will be the same.
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers