Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
lawada
Helper III
Helper III

calculate average delay in (days,hours,minutes,seconds)

i have to calculate the Average delay in orders in (days,hours,minutes,seconds)

first i calculated the duration in seconds :

 

Duration in Seconds =
duration=DATEDIFF(orders[Order PlacedDate],orders[In Progress Order Date],SECOND)
 
then i calculated the count of orders
Orders=Count(Orders[id])
 
after that i found the average delay in seconds : 
averge = SUM(orders[Duration in Seconds])/[orders]

after that i found the average in HH:MM:SS using this formula which i found also in the community
avg HH:MM:SS =
// We start with a duration in number of seconds

// There are 3,600 seconds in an hour
VAR Hours =
INT ( [averge] / 3600)
// There are 60 seconds in a minute
VAR Minutes =
INT ( MOD( [averge] - ( Hours * 3600 ),3600 ) / 60)
// Remaining seconds are the remainder of the seconds divided by 60 after subtracting out the hours
VAR Seconds =
ROUNDUP(MOD ( MOD( [averge] - ( Hours * 3600 ),3600 ), 60 ),0) // We round up here to get a whole number
// These intermediate variables ensure that we have leading zero's concatenated onto single digits
// Hours with leading zeros
VAR H =
IF ( LEN ( Hours ) = 1,
CONCATENATE ( "0", Hours ),
CONCATENATE ( "", Hours )
)
// Minutes with leading zeros
VAR M =
IF (
LEN ( Minutes ) = 1,
CONCATENATE ( "0", Minutes ),
CONCATENATE ( "", Minutes )
)
// Seconds with leading zeros
VAR S =
IF (
LEN ( Seconds ) = 1,
CONCATENATE ( "0", Seconds ),
CONCATENATE ( "", Seconds )
)
// Now return hours, minutes and seconds with leading zeros in the proper format "hh:mm:ss"
RETURN
CONCATENATE (
H,
CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) )
)
 
 
And now i have to use this formula to calculate the Average delay in Days , Hours , minutes, Seconds
 
any suggestions please
3 REPLIES 3
Fowmy
Super User
Super User

@lawada 


I have modified your measure and you use the follwing :

 

Avg Delay = 
var vSeconds = 
DIVIDE(
    DATEDIFF(orders[Order PlacedDate],orders[In Progress Order Date],SECOND),
    Count(Orders[id])
)
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"

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

thank you this calculation worked for me, however im getting the seconds with decimilas how can i get rid of the decimals ?

lawada_0-1606723590560.png

 

CNENFRNL
Community Champion
Community Champion

@lawada , you might want to try an interesting trick

Untitled.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors