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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
GoldBarz
New Member

How to combine two columns and add a time offset

Hi, I have two recovery % values in two seperate columns associated with a single date (without a time stamp) in my query editor. I would like to seperate shift 1 and shift 2 such that shift 2 is offset 12 hours from shift 1 and they can be compared all in a single coumn. Does anyone know how I could go about this? Thank you very much, your help is most appreciated.

GoldBarz_0-1643298013443.png

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@GoldBarz start a new query, click advanced editor and paste this code, you can tweak it as you see fit

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZZNJjgMxCEWvEpVUu4gwGLD7KlHuf42u8hiTnRdPwH/g9/ugF70YmR/4h3g8DxfQdN4PAvLz+DxvhjdGFUQqk8F0MLIxGUH8ZjID22DSzjAUrQyByWB0Z655Wh0B58HYzjhQroxBnvN4rEO1jjukMpi8MZZB6jymoDiYsvtJPZcjlOmHcIcIHM9m02cwCqavbjjST0PEURFzh8qMTxKhTB2S1W6X7VYz1QdPAaQxXWqQ1jPokMUTsaYgAdOEPLYz6u1sVdqFX7sg64dU1ky78TtUU4Cgsx3jz3pleFoQxZvMoxLmCXGcqSsoUBYkcXeW++C+oGC81N9RHzrXwhqhkvrtfkEWFVA7lcv4DX3+AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Met Bal % Au Rec - Shift 1" = _t, #"Met Bal % Au Rec - Shift 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Met Bal % Au Rec - Shift 1", Percentage.Type}, {"Met Bal % Au Rec - Shift 2", Percentage.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Met Bal % Au Rec - Shift 1", "1"}, {"Met Bal % Au Rec - Shift 2", "2"}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Date"}, "Attribute", "Value"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Attribute", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "DateTime", each [Date]+(#duration(0,if [Attribute] = 1 then 6 else 12,0,0)), type datetime),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"DateTime", "Value"})
in
    #"Removed Other Columns"

 

parry2k_0-1643304606448.png

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@GoldBarz start a new query, click advanced editor and paste this code, you can tweak it as you see fit

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZZNJjgMxCEWvEpVUu4gwGLD7KlHuf42u8hiTnRdPwH/g9/ugF70YmR/4h3g8DxfQdN4PAvLz+DxvhjdGFUQqk8F0MLIxGUH8ZjID22DSzjAUrQyByWB0Z655Wh0B58HYzjhQroxBnvN4rEO1jjukMpi8MZZB6jymoDiYsvtJPZcjlOmHcIcIHM9m02cwCqavbjjST0PEURFzh8qMTxKhTB2S1W6X7VYz1QdPAaQxXWqQ1jPokMUTsaYgAdOEPLYz6u1sVdqFX7sg64dU1ky78TtUU4Cgsx3jz3pleFoQxZvMoxLmCXGcqSsoUBYkcXeW++C+oGC81N9RHzrXwhqhkvrtfkEWFVA7lcv4DX3+AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Met Bal % Au Rec - Shift 1" = _t, #"Met Bal % Au Rec - Shift 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Met Bal % Au Rec - Shift 1", Percentage.Type}, {"Met Bal % Au Rec - Shift 2", Percentage.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Met Bal % Au Rec - Shift 1", "1"}, {"Met Bal % Au Rec - Shift 2", "2"}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Date"}, "Attribute", "Value"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Attribute", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "DateTime", each [Date]+(#duration(0,if [Attribute] = 1 then 6 else 12,0,0)), type datetime),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"DateTime", "Value"})
in
    #"Removed Other Columns"

 

parry2k_0-1643304606448.png

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@GoldBarz Got it, can you also paste the sample data into the table format instead of an image.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

DateMet Bal % Au Rec - Shift 1Met Bal % Au Rec - Shift 2
1/1/2022 0:0073.54%71.17%
1/2/2022 0:0055.33%78.65%
1/3/2022 0:0080.37%82.26%
1/4/2022 0:0082.95%81.63%
1/5/2022 0:0083.57%83.72%
1/6/2022 0:0087.18%86.85%
1/7/2022 0:0083.17%77.49%
1/8/2022 0:0068.35%65.50%
1/9/2022 0:0074.37%70.97%
1/10/2022 0:0071.70%73.73%
1/11/2022 0:0078.30%81.66%
1/12/2022 0:0082.22%81.92%
1/13/2022 0:0082.81%81.33%
1/14/2022 0:0076.50%76.29%
1/15/2022 0:0074.40%75.54%
1/16/2022 0:0073.67%74.21%
1/17/2022 0:0076.61%76.64%
1/18/2022 0:0077.16%78.99%
1/19/2022 0:0081.32%80.51%
1/20/2022 0:0083.13%81.91%
1/21/2022 0:0080.82%80.08%
1/22/2022 0:0077.40%79.98%
1/23/2022 0:0078.68%78.78%
1/24/2022 0:0079.65%79.53%
1/25/2022 0:0079.94%86.53%
1/26/2022 0:0081.10%84.23%
GoldBarz
New Member

Expected output would look like this:

 

 

Date

Recovery
1/1/2022 6:0073.54
1/1/2022 18:0071.17
1/2/2022 6:0055.33
1/2/2022 18:0078.65
1/3/2022 6:0080.37
1/3/2022 18:0082.26
1/4/2022 6:0082.95
1/4/2022 18:0081.63
1/5/2022 6:0083.57
1/5/2022 18:0083.72
1/6/2022 6:0087.18
1/6/2022 18:0086.85

 

parry2k
Super User
Super User

@GoldBarz not super clear, can you provide the expected output.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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