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