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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kafisch
New Member

Convert opening time intervals into columns

Sorry,

in Excel Power Query Editor I need to split up the hours colum into new columns for each weekday:

Monday                         |Tuesday                         |....

10:00-15:00;16:00-22:00|10:00-15:00;16:00-20:00|....

 

out of a list of records like this ones: 

"hours": [
{
"weekday": 1,
"openFrom": "10:00",
"openTil": "15:00"
},
{
"weekday": 1,
"openFrom": "16:00",
"openTil": "22:00"
},
{
"weekday": 2,
"openFrom": "10:00",
"openTil": "15:00"
},
{
"weekday": 2,
"openFrom": "16:00",
"openTil": "20:00"
},

....
]

 

Power Query Editor 2020-08-12 210551.jpg

What would be the best approach here? Thanks!

1 ACCEPTED SOLUTION

6 REPLIES 6
v-alq-msft
Community Support
Community Support

Hi, @kafisch 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end

Table:

d1.png

 

Here are the codes in 'Query Editor'.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSwMjDQNTQFktaGZiC2kRGQVNLBJmMAkbHEJYGpxRCkVik2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Monday = _t, Tuesday = _t, Wednesday = _t, Thursday = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Monday", type text}, {"Tuesday", type text}, {"Wednesday", type text}, {"Thursday", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Name", "Value"),
    Custom1 = Table.TransformColumns(#"Unpivoted Columns",{"Value",each
Text.Split(_,";")
}
),
    #"Added Custom" = Table.AddColumn(Custom1, "Custom", each Record.FromTable(
    let n=[Name] in
    Table.SelectRows(#"Custom1",each [Name]=n)
)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Name", "Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "hours"}})
in
    #"Renamed Columns"

 

Result:

d2.png

 

Best Regards

Allan

 

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

 

parry2k
Super User
Super User

@kafisch you should able to use the JSON file as a data source and then in PQ expand/transform to extract the data.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos 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.

Sorry, @parry2k this will add additional rows. I need to split up the hours list into several columns. One column for each working day with the corresponding time intervalls.

@kafisch once you have rows, you can use pivot to convert to columns 

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos 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.

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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