cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
AntBI26
Frequent Visitor

Calculate of Total Time from two measures

Hello all, 

 

I have firstly created two measures to calculate the overall time that some tasks takes. 

 

1st measure: this calculate the overall TIME for 5 tasks (Measure's name = TimeActivities)

2nd measure: this calculate the time taken for the admin of one of the task and was calulated based on a separate data/table.                                 (Measure's name = TimeActivities2 )

 

I now want to add the two TIME measures together to get an overall time, but somehow cannot do it. Could anyone advise ?

 

Just for note, both of the earlier measures follows this principle to get hh:mm:ss: 

 

TimeActivities2 =
VAR TotalSeconds=SUMX('Sheet1',HOUR('Sheet1'[TimeOverall])*3600+MINUTE('Sheet1'[TimeOverall])*60+SECOND('Sheet1'[TimeOverall]))
VAR Days =TRUNC(TotalSeconds/3600/24)
VAR Hors = TRUNC((TotalSeconds-Days*3600*24)/3600)
VAR Mins =TRUNC(MOD(TotalSeconds,3600)/60)
VAR Secs = MOD(TotalSeconds,60)
return IF((Hors + (Days*24))<10,"0"&(Hors + (Days*24)),(Hors + (Days*24)))&":"&IF(Mins<10,"0"&Mins,Mins)&":"&IF(Secs<10,"0"&Secs,Secs)
1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @AntBI26 - To return time in hh:mm calculate the overall time by adding the times from timeactivity and timeactivitity2 and returning the result in the hh:mm

 

TotalTimeFormatted =
VAR TimeString1 = [TimeActivities]
VAR Hours1 = VALUE(LEFT(TimeString1, 2))
VAR Minutes1 = VALUE(MID(TimeString1, 4, 2))
VAR Seconds1 = VALUE(RIGHT(TimeString1, 2))
VAR TotalSeconds1 = (Hours1 * 3600) + (Minutes1 * 60) + Seconds1

VAR TimeString2 = [TimeActivities2]
VAR Hours2 = VALUE(LEFT(TimeString2, 2))
VAR Minutes2 = VALUE(MID(TimeString2, 4, 2))
VAR Seconds2 = VALUE(RIGHT(TimeString2, 2))
VAR TotalSeconds2 = (Hours2 * 3600) + (Minutes2 * 60) + Seconds2

VAR TotalSeconds = TotalSeconds1 + TotalSeconds2
VAR Hours = TRUNC(TotalSeconds / 3600)
VAR Minutes = TRUNC(MOD(TotalSeconds, 3600) / 60)
VAR Seconds = MOD(TotalSeconds, 60)
RETURN
FORMAT(Hours, "00") & ":" &
FORMAT(Minutes, "00") & ":" &
FORMAT(Seconds, "00")

 

Hope it works, please check

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
AntBI26
Frequent Visitor

Thank you both, I impemented @rajendraongole1 solution, as it was easier to execute. Best wishes.

rajendraongole1
Super User
Super User

Hi @AntBI26 - To return time in hh:mm calculate the overall time by adding the times from timeactivity and timeactivitity2 and returning the result in the hh:mm

 

TotalTimeFormatted =
VAR TimeString1 = [TimeActivities]
VAR Hours1 = VALUE(LEFT(TimeString1, 2))
VAR Minutes1 = VALUE(MID(TimeString1, 4, 2))
VAR Seconds1 = VALUE(RIGHT(TimeString1, 2))
VAR TotalSeconds1 = (Hours1 * 3600) + (Minutes1 * 60) + Seconds1

VAR TimeString2 = [TimeActivities2]
VAR Hours2 = VALUE(LEFT(TimeString2, 2))
VAR Minutes2 = VALUE(MID(TimeString2, 4, 2))
VAR Seconds2 = VALUE(RIGHT(TimeString2, 2))
VAR TotalSeconds2 = (Hours2 * 3600) + (Minutes2 * 60) + Seconds2

VAR TotalSeconds = TotalSeconds1 + TotalSeconds2
VAR Hours = TRUNC(TotalSeconds / 3600)
VAR Minutes = TRUNC(MOD(TotalSeconds, 3600) / 60)
VAR Seconds = MOD(TotalSeconds, 60)
RETURN
FORMAT(Hours, "00") & ":" &
FORMAT(Minutes, "00") & ":" &
FORMAT(Seconds, "00")

 

Hope it works, please check

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





bhanu_gautam
Super User
Super User

@AntBI26 , Try using below measure

 

OverallTime =
VAR TotalSeconds1 = SUMX('Sheet1', HOUR('Sheet1'[TimeOverall1]) * 3600 + MINUTE('Sheet1'[TimeOverall1]) * 60 + SECOND('Sheet1'[TimeOverall1]))
VAR TotalSeconds2 = SUMX('Sheet2', HOUR('Sheet2'[TimeOverall2]) * 3600 + MINUTE('Sheet2'[TimeOverall2]) * 60 + SECOND('Sheet2'[TimeOverall2]))
VAR TotalSeconds = TotalSeconds1 + TotalSeconds2
VAR Days = TRUNC(TotalSeconds / 3600 / 24)
VAR Hours = TRUNC((TotalSeconds - Days * 3600 * 24) / 3600)
VAR Minutes = TRUNC(MOD(TotalSeconds, 3600) / 60)
VAR Seconds = MOD(TotalSeconds, 60)
RETURN
IF((Hours + (Days * 24)) < 10, "0" & (Hours + (Days * 24)), (Hours + (Days * 24))) & ":"
& IF(Minutes < 10, "0" & Minutes, Minutes) & ":"
& IF(Seconds < 10, "0" & Seconds, Seconds)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!





Helpful resources

Announcements
Sticker Challenge

Join our Community Sticker Challenge

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

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