Forum Discussion

Babycakes_00's avatar
Babycakes_00
Helper I
1 year ago
Solved

Roster by Location

HI There,   I am importing a simple table and wish to have the locations as the headers to  - using power query:)   See attached file   Tab 1 is current Format Sheet 2 is desired format,   C...
  • Omid_Motamedise's avatar
    Omid_Motamedise
    1 year ago

    Related to your question, just copy and past the next code into advance editor.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZRLq8IwEIX/SuhaMJna51IXirhTcCEueiFooA9p4v9XaavxTptOwWUOnY8zZ6ZzOnliMRd8DhwWjIcp597MlkTcSMusNmyvipuuytfzrlUptWbCO8++GQlmRI20llV9kWyj8txGwH+E8AcRy+qPrZ5WZP18HKQ2nYHgY4C31eFbAj8NEmJ1F0GAIlhlyuSqZMerMrKnARKEYiHB1ZF7CtjBMMM9Bet7norgGwHQSNuskJrtC2WuPbsQ4hxClMMPECNhRJgRTbQRY0Q8DQECjcSSaGOlMXZKZyRG93f1+RhYToCPg7ZrSyJ2QWKMdEFiOBechhiYaYvw8Tz8qWmQGCNp4KMLPRfT7YPEGPGBzw5MPV00hsPH+QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t, Employee = _t, Location = _t]),
        #"Grouped Rows" = Table.Group(Source, {"Location"}, {{"Count", each _, type table [Start=nullable text, End=nullable text, Employee=nullable text, Location=nullable text]}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",0)),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Location", "Count"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Start", "End", "Employee", "Location", "Index"}, {"Start", "End", "Employee", "Location", "Index"}),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Expanded Custom", {"Location", "Index"}, "Attribute", "Value"),
        #"Merged Columns" = Table.CombineColumns(#"Unpivoted Columns",{"Location", "Attribute"},Combiner.CombineTextByDelimiter(" | ", QuoteStyle.None),"Merged"),
        #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value"),
        #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
    in
        #"Removed Columns1"

    result in the next image

     

     

     

    as it is impossible have two row headers in power query and also header columns should be unique (cant have three column with name Business 1) I combined your first two rows.



    If this answer helped resolve your issue, please consider marking it as the accepted answer. And if you found my response helpful, I'd appreciate it if you could give me kudos. 

    Thank you!