Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
This is for a calculated column.
Whenever the [exit time] is the next day, but within 24 hours of [enter time], I get a negative result for minutes.
All other aspects, except this, are working fine.
Minutes =
VAR _NonWorkingDays =
CALCULATE(
COUNTROWS('Calendar'),
'Calendar'[Day Type] <> "Work Day"
)
VAR _WorkTimeElapsed =
DATEDIFF(AuditLog[Enter_Time],AuditLog[Exit_Time], MINUTE) - (_NonWorkingDays* 24 * 60)
RETURN
_WorkTimeElapsed
I think it is because your exit time is before enter time in the 24 hour period.
Can you post some data ?
Minutes | Enter_Time | Exit_Time |
-32 | 2/19/2024 8:47:00 AM | 2/20/2024 8:15:00 AM |
-153 | 6/19/2024 11:32:00 AM | 6/20/2024 8:59:00 AM |
-328 | 2/19/2024 2:18:00 PM | 2/20/2024 8:50:00 AM |
Hi @noannish ,
According to your statement, I think your result is correct.
Working backwards from the results you gave, I think the _NonWorkingDays = 1 and (_NonWorkingDays* 24 * 60) in your code will return 1440.
Since I don't know exactly what your Calendar table looks like, if there is a issue with this part of the result, please check it.
Please make sure the datediff(minutes) between [Enter Time] and [Exit Time].
I think the datediff(minutes) in your sample are all less than 1440, so datediff(minutes) - (_NonWorkingDays* 24 * 60) will return negative result.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Try something like this in the Return statement
RETURN IF(
_WorkTimeElapsed < 0,
_WorkTimeElapsed + (24 * 60),
_WorkTimeElapsed
)
User | Count |
---|---|
25 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
27 | |
13 | |
13 | |
10 | |
6 |