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

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

Reply
smjzahid
Helper V
Helper V

How to add TIME values in DAX or Power Query

I have a colum of type TIME datatype and I want to sum the values in this column to find out TOTAL HOURS or TOTAL MINUTES WORKED.

 

Doing this in excel is really straight forward, but I cannot do this in Power BI Desktop using (DAX or Power Query)

smjzahid_0-1635411571956.png

 

How do I do this in DAX or Power Query, 

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi  @smjzahid ,

 

Using below M codes to get the total hours and minutes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrIyNLAyMFWK1YlWMrAyArINoGwDA6CUUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Total Time" = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Total Time", type time}}, "zh-CN"),
    #"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "hours", each Time.Hour([Total Time])+Time.Minute([Total Time])/60+Time.Second([Total Time])/3600),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Total hours", each List.Sum(#"Added Custom"[hours])),
    #"Extracted Text Range" = Table.TransformColumns(#"Added Custom1", {{"Total hours", each Text.Middle(Text.From(_, "en-US"), 0, 5), type text}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Extracted Text Range",{{"Total hours", type number}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type", "Minutes", each Time.Hour([Total Time])*60+Time.Minute([Total Time])+Time.Second([Total Time])/60),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Total Minutes", each List.Sum(#"Added Custom2"[Minutes])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Minutes", "hours"})
in
    #"Removed Columns"

And you will see:

vkellymsft_0-1635824031867.png

 

Or you could create 4 columns using dax expressions to get the result.

For details,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

4 REPLIES 4
FrankG
Regular Visitor

Hi, 

Maybe there are more elgant solutions, but I think the below will work:

 

#"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Time.ToRecord(Time.From([Time]/86400))),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"Hour", "Minute", "Second"}, {"Custom.Hour", "Custom.Minute", "Custom.Second"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "DateTime", each DateTime.From([Date] + #duration(0,8,[Custom.Minute],[Custom.Second])), type datetime)

 

FrankG_0-1663334172321.png

 

v-kelly-msft
Community Support
Community Support

Hi  @smjzahid ,

 

Using below M codes to get the total hours and minutes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrIyNLAyMFWK1YlWMrAyArINoGwDA6CUUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Total Time" = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Total Time", type time}}, "zh-CN"),
    #"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "hours", each Time.Hour([Total Time])+Time.Minute([Total Time])/60+Time.Second([Total Time])/3600),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Total hours", each List.Sum(#"Added Custom"[hours])),
    #"Extracted Text Range" = Table.TransformColumns(#"Added Custom1", {{"Total hours", each Text.Middle(Text.From(_, "en-US"), 0, 5), type text}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Extracted Text Range",{{"Total hours", type number}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type", "Minutes", each Time.Hour([Total Time])*60+Time.Minute([Total Time])+Time.Second([Total Time])/60),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Total Minutes", each List.Sum(#"Added Custom2"[Minutes])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Minutes", "hours"})
in
    #"Removed Columns"

And you will see:

vkellymsft_0-1635824031867.png

 

Or you could create 4 columns using dax expressions to get the result.

For details,pls see attached.

 

Best Regards,
Kelly

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

mahoneypat
Microsoft Employee
Microsoft Employee

Please see this article and videos.

Calculate and Format Durations in DAX – Hoosier BI

 

Pat





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


HotChilli
Super User
Super User

A Time datatype in powerbi/power query is a time of the day e.g. 12.51pm  so adding them doesn't make sense.

If you can change the datatype to be duration in Power Query there are functions to get TotalHours or TotalMinutes.

 

In DAX, you can parse your time as a datetime or text and use an algorithm to work out total hours or minutes .  I think there are some blog posts on here about it.  There are definitely lots of posts about it.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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 Kudoed Authors