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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
HamidBee
Power Participant
Power Participant

How can I create a DAX measure to add time in hh:mm format?

I am working with the following data:

 

LetterDuration
A04:40
A05:20
B01:20
B05:43
C06:34
C02:45
D09:21
D10:12
E04:39
E05:30

 

What I would like to be able to do is to find the total duration for each letter but to keep it in the hh:mm format. I'd like the hh to be able to exceed 24. I would like to plot this in a matrix. However when I try to do this it appears that I cannot. Here is a link to the .pbix file:

 

https://www.mediafire.com/file/8acsm9irdvoxtcv/Adding_Times.pbix/file

 

Thanks in advance.

3 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@HamidBee 

here is a workaround for you.

1. create a min column

duration min = hour('Table'[Duration])*60+MINUTE('Table'[Duration])
1.PNG
 
2. create a measure
Measure =
VAR _sum=sum('Table'[duration min])
VAR _hour=right("0"&ROUNDDOWN(_sum/60,0),2)
VAR _min=right("0"&mod(_sum,60),2)
return _hour&":"&_min
 
2.PNG
 
pls see the attachment below

 





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

Proud to be a Super User!




View solution in original post

vojtechsima
Super User
Super User

Hello, @HamidBee

vojtechsima_0-1660128427729.png

Total Duration = 

var Hours = CALCULATE( SUMX('Table', HOUR('Table'[Duration])), ALLEXCEPT('Table','Table'[Letter]))
var Minutes = CALCULATE( SUMX('Table', MINUTE('Table'[Duration])), ALLEXCEPT('Table','Table'[Letter]))

var MinutesForHours = DIVIDE ( Minutes , 60 )
var SingleMinutes = MOD(Minutes, 60)
var HoursWithMinutes = TRUNC( Hours + MinutesForHours)

var Result = FORMAT(HoursWithMinutes, "00") & ":" & FORMAT(SingleMinutes, "00")


return Result

 

View solution in original post

@HamidBee 

That means if the hour is one digit, then add 0 before it. 

if the hour is two digits, then add 0 before it and get the 2 digits from the right side.

However, here is a problem. If the hour is larger than 99, this solution will not work.

you may change to this.

Measure =
VAR _sum=sum('Table'[duration min])
VAR _hour=if(ROUNDDOWN(_sum/60,0)<10,"0"&ROUNDDOWN(_sum/60,0),ROUNDDOWN(_sum/60,0)
VAR _min=if(mod(_sum,60)<10,"0"&mod(_sum,60),mod(_sum,60))
return _hour&":"&_min

 





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

Proud to be a Super User!




View solution in original post

8 REPLIES 8
vojtechsima
Super User
Super User

Hello, @HamidBee

vojtechsima_0-1660128427729.png

Total Duration = 

var Hours = CALCULATE( SUMX('Table', HOUR('Table'[Duration])), ALLEXCEPT('Table','Table'[Letter]))
var Minutes = CALCULATE( SUMX('Table', MINUTE('Table'[Duration])), ALLEXCEPT('Table','Table'[Letter]))

var MinutesForHours = DIVIDE ( Minutes , 60 )
var SingleMinutes = MOD(Minutes, 60)
var HoursWithMinutes = TRUNC( Hours + MinutesForHours)

var Result = FORMAT(HoursWithMinutes, "00") & ":" & FORMAT(SingleMinutes, "00")


return Result

 

Thanks for this method it also works perfectly.

saravanan_p
Resolver III
Resolver III

create a column in table :

column = 

(duration_test[H] *60) + duration_test[m]

ANd write measure as 
duration_m =
var d = sum(duration_test[Column])
var h =right("0" & rounddown(d/60,0),2)
var m=right("0" & MOD(d,60),2)
return
h&":"&m
@HamidBee  The reply from @ryan_mayu  is also the same. Both works and request you to mark both as solutions.
Thank you Guys, Good Day

@ryan_mayuand @HamidBee Dont forget to give thumps up

ryan_mayu
Super User
Super User

@HamidBee 

here is a workaround for you.

1. create a min column

duration min = hour('Table'[Duration])*60+MINUTE('Table'[Duration])
1.PNG
 
2. create a measure
Measure =
VAR _sum=sum('Table'[duration min])
VAR _hour=right("0"&ROUNDDOWN(_sum/60,0),2)
VAR _min=right("0"&mod(_sum,60),2)
return _hour&":"&_min
 
2.PNG
 
pls see the attachment below

 





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

Proud to be a Super User!




I would like to ask what the following means:

 

VAR _hour=right("0"&ROUNDDOWN(_sum/60,0),2)


I understand it to mean that you are converting the minutes into hours and then removing any decimal places by using '2'. I'm familiar with what RIGHT does but I don't understand why "0" was used and why "&" was used.


VAR _min=right("0"&mod(_sum,60),2)


I believe you are taking the sum here and dividing it by 60 and keeping only the remainder. Again I'm not too sure what the RIGHT function and '2' are for., 

If you can please clarify these points that would be greatly appreciated. 

Thank you.

 

@HamidBee 

That means if the hour is one digit, then add 0 before it. 

if the hour is two digits, then add 0 before it and get the 2 digits from the right side.

However, here is a problem. If the hour is larger than 99, this solution will not work.

you may change to this.

Measure =
VAR _sum=sum('Table'[duration min])
VAR _hour=if(ROUNDDOWN(_sum/60,0)<10,"0"&ROUNDDOWN(_sum/60,0),ROUNDDOWN(_sum/60,0)
VAR _min=if(mod(_sum,60)<10,"0"&mod(_sum,60),mod(_sum,60))
return _hour&":"&_min

 





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

Proud to be a Super User!




@ryan_mayu Man O Man, super fast. Same findings. Cheers. 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors