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
    7

    Cool

    you can try Power Query (excel 2016 and up)
    simple version:
    Code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        Type = Table.TransformColumnTypes(Source,{{"Values", type text}}),
        GR = Table.Group(Type, {"Code"}, {{"GrBy", each Table.Transpose(Table.FromList([Values]))}}),
        Exp = Table.ExpandTableColumn(GR, "GrBy", {"Column1", "Column2", "Column3", "Column4"}, {"Column1", "Column2", "Column3", "Column4"}),
        Type2 = Table.TransformColumnTypes(Exp,{{"Column1", type number}, {"Column2", type number}, {"Column3", type number}, {"Column4", type number}})
    in
        Type2
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    Code Values Code Column1 Column2 Column3 Column4
    2
    1001
    2101
    1001
    2101
    5205
    2605
    9285
    3
    1001
    5205
    2604
    4256
    7458
    3555
    4
    1001
    2605
    5
    1001
    9285
    6
    2604
    4256
    7
    2604
    7458
    8
    2604
    3555
    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

  2. #2
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    12
    Quote Originally Posted by sandy666 View Post
    you can try Power Query (excel 2016 and up)simple version:
    Doesn't this assume a max of 4 repeated codes?
    I was waiting for the OP to come back before posting.
    I did a PQ offering. A bit convoluted (I'm sure you can streamline it):
    The query:
    Code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Grouped Rows" = Table.Group(Source, {"Code"}, {{"grp", each _, type table [Code=number, Values=number]}}),
        #"Invoked Custom Function" = Table.Combine(Table.AddColumn(#"Grouped Rows", "fnTranspose2", each fnTranspose2([grp]))[fnTranspose2])
    in
        #"Invoked Custom Function"
    The called function named fnTranspose2:
    Code:
    (tbl)=> [AddIndx = Table.AddIndexColumn(tbl, "Index", 1, 1, Int64.Type),
        AddPrefix = Table.TransformColumns(AddIndx, {{"Index", each "Value" & Text.From(_), type text}}),
        TakeColms = Table.ReorderColumns(AddPrefix,{"Index", "Code", "Values"}),
        Result = Table.Pivot(TakeColms, List.Distinct(TakeColms[Index]), "Index", "Values", List.Sum)][Result]
    Also a formula approach:
    In one cell (eg. cell F8):
    =UNIQUE(Table1[Code])
    In the cell to the right:
    =TRANSPOSE(FILTER(Table1[Values],Table1[Code]=F8))
    copied down as far as necessary. F8 is the address of that cell to the right.
    Last edited by p45cal; 08-03-2022 at 01:33 AM.

  3. #3
    Junior Member
    Join Date
    Oct 2021
    Posts
    3
    Rep Power
    0
    it works. Let me try for more data.
    Thanks

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
  •