Results 1 to 8 of 8

Thread: Transpose 2 column [Key, values] list to mulit column [unique Key, Value1, value2, value3, ......] list

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sir Moderator sandy666's Avatar
    Join Date
    May 2018
    Posts
    240
    Rep Power
    8
    Code from above was for example from OP
    Here is more flexible code
    Code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        TypeRD = Table.Distinct(Table.TransformColumnTypes(Source,{{"Values", type text}})),
        GR = Table.Group(TypeRD, {"Code"}, {{"GrBy", each Table.Transpose(Table.FromList([Values]))}}),
        MT = Table.AddColumn(GR, "ColCount", each Table.ColumnCount([GrBy])),
        LD = List.Distinct(List.Combine(Table.AddColumn(MT, "ColNames", each Table.ColumnNames([GrBy]))[ColNames])),
        EXRC = Table.RemoveColumns(Table.ExpandTableColumn(MT,"GrBy",LD),{"ColCount"}),
        UNP = Table.UnpivotOtherColumns(EXRC, {"Code"}, "Attribute", "Value"),
        RPL = Table.ReplaceValue(Table.TransformColumnTypes(UNP,{{"Value", Int64.Type}}),"Column","Value",Replacer.ReplaceText,{"Attribute"}),
        PVT = Table.Pivot(RPL, List.Distinct(RPL[Attribute]), "Attribute", "Value")
    in
        PVT
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    1
    Code Values Code Value1 Value2 Value3 Value4 Value5 Value6 Value7 Value8
    2
    1001
    2101
    1001
    2101
    2605
    5205
    9285
    3
    1001
    2605
    2604
    3555
    4256
    7458
    4
    1001
    5205
    3111
    1218
    1222
    1226
    1230
    1234
    1235
    1236
    1237
    5
    1001
    9285
    6
    2604
    3555
    7
    2604
    4256
    8
    2604
    7458
    9
    3111
    1218
    10
    3111
    1222
    11
    3111
    1226
    12
    3111
    1230
    13
    3111
    1234
    14
    3111
    1234
    15
    3111
    1235
    16
    3111
    1236
    17
    3111
    1237


    btw. functions UNIQUE and FILTER are for EX365 and higher but not lower version
    Last edited by sandy666; 08-03-2022 at 05:12 AM.
    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: 23
    Last Post: 07-27-2014, 06:06 PM
  2. Replies: 10
    Last Post: 05-23-2013, 12:30 PM
  3. Numbered List Of Unique Values
    By xander1981 in forum Excel Help
    Replies: 6
    Last Post: 01-21-2013, 06:10 PM
  4. shortcut key to list of macros
    By Rasm in forum Excel Help
    Replies: 4
    Last Post: 01-10-2013, 03:19 PM
  5. Replies: 2
    Last Post: 01-07-2012, 12:11 AM

Posting Permissions

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