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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rockingmark
Advocate I
Advocate I

Using mCODE Subtract a column of minutes from a column with a date stamp

Hi,  I have a table with a column of date/time timestamps called "Time Stamp" and I want to subtract a duration in minutes (on the same row in column Minutes) from the timestamp.  How can this be done? Desired column shown below.  Many thanks

  Desired Column from mcode calculation
Time stampMinutestimestamp column subtracted Minutes column
31/08/2023 17:59:4212.531/08/2023 17:47:12
31/08/2023 09:56:0413.0031/08/2023 09:43:04
31/08/2023 19:24:371.2531/08/2023 19:23:22
1 ACCEPTED SOLUTION
gmsamborn
Super User
Super User

Hi @rockingmark 

 

If you divide [Minutes] by (24 * 60), the result is the fraction of a day which converts to a duration.

 

 

let
    Source = SourceTable,
    #"Added Custom" = Table.AddColumn(Source, "Days", each [Minutes] / ( 24 * 60 )),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Days", type duration}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "New Timestamp", each [Time stamp] - [Days]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"New Timestamp", type datetime}})
in
    #"Changed Type1"

 

 

 

Subtract minutes from timestamp.pbix



Proud to be a Super User!

daxformatter.com makes life EASIER!

View solution in original post

3 REPLIES 3
gmsamborn
Super User
Super User

Hi @rockingmark 

 

If you divide [Minutes] by (24 * 60), the result is the fraction of a day which converts to a duration.

 

 

let
    Source = SourceTable,
    #"Added Custom" = Table.AddColumn(Source, "Days", each [Minutes] / ( 24 * 60 )),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Days", type duration}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "New Timestamp", each [Time stamp] - [Days]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"New Timestamp", type datetime}})
in
    #"Changed Type1"

 

 

 

Subtract minutes from timestamp.pbix



Proud to be a Super User!

daxformatter.com makes life EASIER!

Cool Thanks, I was missing that you can convert minutes to duration so your example massively helped me 

HotChilli
Super User
Super User

Do you want the minutes column e.g. 12.5 to be a duration of 12 minutes 30 secs?

If so,

Number.RoundDown([Minutes])

will give the whole minutes.

60 * Number.Mod([Minutes],1)

will give the seconds.

You use those to construct a #duration() https://learn.microsoft.com/en-us/powerquery-m/sharpduration and subtract it from the Time Stamp column

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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