Results 1 to 1 of 1

Thread: PQ - Transform data from vertical to horizontal with Table.FromRecords

  1. #1
    Sir Moderator sandy666's Avatar
    Join Date
    May 2018
    Posts
    236
    Rep Power
    7

    Cool PQ - Transform data from vertical to horizontal with Table.FromRecords

    Code:
    let
        TFR = Table.FromRecords({[Column = "Name"], [Column = "Address"], [Column = "City"], [Column = "State Zip"], [Column = "Telephone"]}),
        USC = Table.Unpivot(TFR, {"Column"}, "Attribute", "Value"),
        IndexTFR = Table.AddIndexColumn(USC, "Index", 1, 1),
        TCC = Table.CombineColumns(Table.TransformColumnTypes(IndexTFR, {{"Index", type text}}, "en-GB"),{"Attribute", "Index"},Combiner.CombineTextByDelimiter(".", QuoteStyle.None),"Merged"),
        Pivot = Table.Pivot(TCC, List.Distinct(TCC[Merged]), "Merged", "Value"),
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        Filter = Table.SelectRows(Source, each ([raw] <> null)),
        Index = Table.AddIndexColumn(Filter, "Index", 0, 1),
        IDC = Table.TransformColumns(Index, {{"Index", each Number.IntegerDivide(_, 5), Int64.Type}}),
        Group = Table.Group(IDC, {"Index"}, {{"Count", each _, type table}}),
        List = Table.AddColumn(Group, "Column", each [Count][raw]),
        Extract = Table.TransformColumns(List, {"Column", each Text.Combine(List.Transform(_, Text.From), "="), type text}),
        Split = Table.SplitColumn(Extract, "Column", Splitter.SplitTextByDelimiter("=", QuoteStyle.Csv), {"Column.1", "Column.2", "Column.3", "Column.4", "Column.5"}),
        RC = Table.RemoveColumns(Split,{"Index", "Count"}),
        TC = Table.Combine({Pivot, RC}),
        Promote = Table.PromoteHeaders(TC, [PromoteAllScalars=true])
    in
        Promote
    source
    planned column names in the result
    result
    raw Name Address City State Zip Telephone
    Miller-Huebl Funeral Home Name Miller-Huebl Funeral Home 1111 South Main Street Aberdeen , SD 57401 (605) 225-8223
    1111 South Main Street Address Schriver's Memorial Mortuary 414 5th Avenue Nw Aberdeen , SD 57401 (605) 225-0691
    Aberdeen City Spitzer-Osthus Funeral Home 320 6th Avenue Se Aberdeen , SD 57401 (605) 225-7025
    , SD 57401 State Zip
    (605) 225-8223 Telephone
    Schriver's Memorial Mortuary
    414 5th Avenue Nw
    Aberdeen
    , SD 57401
    (605) 225-0691
    Spitzer-Osthus Funeral Home
    320 6th Avenue Se
    Aberdeen
    , SD 57401
    (605) 225-7025
    Last edited by sandy666; 10-17-2020 at 04:27 PM.
    sandy
    I know you know but I forgot my Crystal Ball and don't know what you know also I may not remember what I did weeks, months or years ago so answer asap. Thinking doesn't hurt

Similar Threads

  1. Replies: 4
    Last Post: 08-23-2020, 03:04 PM
  2. more about PowerQuery aka Get&Transform (links)
    By sandy666 in forum ETL PQ Tips and Tricks
    Replies: 0
    Last Post: 06-10-2020, 07:43 PM
  3. Append Table data to another table
    By jeremiah_j2k in forum Excel Help
    Replies: 4
    Last Post: 08-10-2017, 09:12 PM
  4. Replies: 5
    Last Post: 12-07-2013, 12:35 PM
  5. Replies: 2
    Last Post: 07-31-2013, 09:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •