Forum Discussion
create total hours from date time
- 21 days ago
Hi Dicken
try sample mcode
let Source = #table( type table [Task = text, Start = datetime, End = datetime], { {"Task A", #datetime(2026, 10, 1, 9, 0, 0), #datetime(2026, 10, 1, 17, 30, 0)}, {"Task B", #datetime(2026, 10, 1, 22, 0, 0), #datetime(2026, 10, 2, 6, 15, 0)}, {"Task C", #datetime(2026, 10, 2, 8, 0, 0), #datetime(2026, 10, 5, 12, 0, 0)}, {"Task D", #datetime(2026, 10, 3, 14, 45, 0), #datetime(2026, 10, 3, 15, 5, 0)}, {"Task E", #datetime(2026, 10, 4, 10, 0, 0), null} } ), AddTotalHours = Table.AddColumn( Source, "Total Hours", each if [Start] = null or [End] = null then null else Number.Round(Duration.TotalHours([End] - [Start]), 2), type number ) in AddTotalHoursPlease give kudos or mark it as resolved once confirmed.
Regards,
Praful
Hi Dicken,
Could you please share a small example of the data and the result you are trying to produce?
For example, it would help to know whether you have:
StartDateTime
EndDateTimeand want the elapsed time between them expressed as total hours, such as 2.5 hours.
Also, are you looking to calculate this in DAX, Power Query, or as a calculated column/measure?
If you can post 3-4 sample rows together with the expected Total Hours result, it should be possible to give you the correct expression without making assumptions.
AI-assisted drafting: AI was used to help structure and phrase this response. I reviewed and validated the technical content before posting.
No, it won't let me I did try posting both the xl solution and my power query
verson, but it would not allow me to publish I just kept getting something aboiut
html tags, i tried both as text and code button.