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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
davidz106
Helper III
Helper III

Subtract only first value of a column

I have two columns (StartTime and EndTime) where I want to create a new custom column where I subtract only first value of StartTime from each value in EndTime. Data time of both columns is Time. Suggestions appreciated.

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

Hi @davidz106 ,

You can get it in Power Query Editor, please find the details in the attachment.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NYzJEQAhCARz4e0DEK9JxTL/NBZhfXZP1+xNCm5UqEOUTtlUIeY8oBxs4GR7bLef4Brcb1hovX6AV3DLvwmdzsLgGWJB5AqB5oNPar8ZaWJzo7BO53w=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StartTime = _t, EndTime = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"StartTime", type time}, {"EndTime", type time}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [EndTime]-#"Changed Type"[StartTime]{0}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type duration}})
in
    #"Changed Type1"

yingyinr_0-1674193369679.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @davidz106 ,

You can get it in Power Query Editor, please find the details in the attachment.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NYzJEQAhCARz4e0DEK9JxTL/NBZhfXZP1+xNCm5UqEOUTtlUIeY8oBxs4GR7bLef4Brcb1hovX6AV3DLvwmdzsLgGWJB5AqB5oNPar8ZaWJzo7BO53w=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StartTime = _t, EndTime = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"StartTime", type time}, {"EndTime", type time}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [EndTime]-#"Changed Type"[StartTime]{0}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type duration}})
in
    #"Changed Type1"

yingyinr_0-1674193369679.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@davidz106 , Min and Max based on what

overall 

 

a new column

datediff(Min(Table[StartTime]), Max(Table[EndTime]) , second)

 

or based on id

 

datediff(MinX(filter(Table, [ID] = earlier([ID]) ),  Table[StartTime]), Max(filter(Table, [ID] = earlier([ID]) ),  Table[EndTime]) , second)

 

Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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