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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

How to create a Conditional Column, in Power Query Editor from Subtracting Timestamps?

 
1 REPLY 1
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZZJLDgMhDEOvUrGu1MQJELjKqPe/RvmoMwGWWH7YCVxX4PAOTESWNXFsB+IPlQ8I8mKuVDYpV9bwfV8BDiQ7XEJdwi0RVcoDlBuMSnK4YtqkXGkm6g0mxNGrPImxSl4loOoE4w0a67hFloHSKkGq0gDTDZZs/XqQd432eMam2PfVwfyABhwulFVqi45xgObAxJtLqmyJoKo2wOKqIm2u9o6jhNsqKuaMTC5S7LBJ2qT2tjOS2ZF5D7D5d5zE+v87DD/madsz25iYn4fFkbZl9hcfkiw15mZZfdty2KCr1Nu2zO8P", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, BATCH_ID = _t, START_DATE = _t, STOP_DATE = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"BATCH_ID", Int64.Type}, {"START_DATE", type datetime}, {"STOP_DATE", type datetime}},"en-GB"),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Duration", each [STOP_DATE]-[START_DATE],type duration),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Idle time", each if [ID]=1 then null else [START_DATE]-#"Added Custom"{[ID]-2}[STOP_DATE],type duration)
in
    #"Added Custom1"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.