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.
Hi All,
I am calculating the duration between planned and actual inbound datetime. I am using the dateiff formula for this and I'm showing the output in this way : 1 days 2 hours 20 minutes. When the actual arival is earlier than planned the calculation will not work. It only working correctly when I use DATEDIFF(average(TBL_SHIPMENTS[Planned DateTime of Arrival]),average(TBL_SHIPMENTS[ACTUAL_ARRIVAL]),SECOND) but I want to see in this way 1 days 2 hours 20 minutes
Solved! Go to Solution.
Hi, @BYENER
According to the data you provided, there should be a difference of about 13 hours. To avoid the time becoming negative, you can add the function ABS(). https://docs.microsoft.com/en-us/dax/abs-function-dax
Measure =
var vSeconds = ABS(DATEDIFF(average(TBL_SHIPMENTS[Planned DateTime of Arrival]),average(TBL_SHIPMENTS[ACTUAL_ARRIVAL]),SECOND))
var vMinutes=int( vSeconds/60)
var vRemainingSeconds=MOD(vSeconds, 60)
var vHours=INT(vMinutes/60)
var vRemainingMinutes=MOD(vMinutes,60)
var vDays=INT(vHours/24)
var vRemainingHours=MOD(vHours,24)
return
vDays&" Days & "&
vRemainingHours&" Hours & "&
vRemainingMinutes&" Minutes & "&
vRemainingSeconds& " Seconds"
Does this match the output you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @BYENER
According to the data you provided, there should be a difference of about 13 hours. To avoid the time becoming negative, you can add the function ABS(). https://docs.microsoft.com/en-us/dax/abs-function-dax
Measure =
var vSeconds = ABS(DATEDIFF(average(TBL_SHIPMENTS[Planned DateTime of Arrival]),average(TBL_SHIPMENTS[ACTUAL_ARRIVAL]),SECOND))
var vMinutes=int( vSeconds/60)
var vRemainingSeconds=MOD(vSeconds, 60)
var vHours=INT(vMinutes/60)
var vRemainingMinutes=MOD(vMinutes,60)
var vDays=INT(vHours/24)
var vRemainingHours=MOD(vHours,24)
return
vDays&" Days & "&
vRemainingHours&" Hours & "&
vRemainingMinutes&" Minutes & "&
vRemainingSeconds& " Seconds"
Does this match the output you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
77 | |
74 | |
42 | |
32 | |
28 |
User | Count |
---|---|
100 | |
93 | |
52 | |
50 | |
48 |