+ Reply to Thread
Results 1 to 3 of 3

Multiple columns of Data, to convert to 2 columns

Hybrid View

  1. #1
    Registered User
    Join Date
    05-05-2020
    Location
    Dublin, Ireland
    MS-Off Ver
    365
    Posts
    2

    Multiple columns of Data, to convert to 2 columns

    Hi,

    Very difficult to put a title on this.....


    Name Age Name Age Name Age Name Age Name Age Name Age
    John 8 Mary 5 Ian 10 Nigel 4 Helen 5 Luke 6
    Paul 6 Ciara 6 Mandy 11 Anne 4 Jorden 4 Stacy 4
    Pat 5 Lucy 3 Cliff 5 Jack 3
    Andy 3 Mark J 7 Kevin 7

    convert to this....

    Name Age
    John 8
    Paul 6
    Pat 5
    Andy 3
    Mary 5
    Ciara 6
    Lucy 4
    etc etc

    Thanks,

    Darren

  2. #2
    Registered User
    Join Date
    05-05-2020
    Location
    Dublin, Ireland
    MS-Off Ver
    365
    Posts
    2

    Re: Multiple columns of Data, to convert to 2 columns

    Names and Ages are obviously already in their own columns....

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,719

    Re: Multiple columns of Data, to convert to 2 columns

    Using Power Query, here is the Mcode. It is a case of unpivoting the rows into columns and manipulating the columns.

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        ChangedDataType = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Age", Int64.Type}, {"Name2", type text}, {"Age3", Int64.Type}, {"Name4", type text}, {"Age5", Int64.Type}, {"Name6", type text}, {"Age7", Int64.Type}, {"Name8", type text}, {"Age9", Int64.Type}, {"Name10", type text}, {"Age11", Int64.Type}}),
        UnpivotedColumns = Table.UnpivotOtherColumns(ChangedDataType, {}, "Attribute", "Value"),
        AddedCustomColumn = Table.AddColumn(UnpivotedColumns, "Age", each Number.ToText([Value])),
        ReplacedErrors = Table.ReplaceErrorValues(AddedCustomColumn, {{"Age", null}}),
        FilledUp = Table.FillUp(ReplacedErrors,{"Age"}),
        SortedRows = Table.Sort(FilledUp,{{"Value", Order.Ascending}}),
        RemovedUneededRows = Table.Skip(SortedRows,18),
        RemovedUneededColumns = Table.RemoveColumns(RemovedUneededRows,{"Attribute"})
    in
        RemovedUneededColumns
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Convert Single column data into multiple columns
    By chsaleem in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-29-2019, 04:16 AM
  2. [SOLVED] Convert multiple columns into one - but keep the first 6 columns repeated
    By phpolicylady in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-28-2016, 08:11 PM
  3. [SOLVED] Convert multiple rows of data into 3 columns in Excel
    By jonphillips in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-17-2013, 08:38 AM
  4. Trying to convert multiple columns into one row of data...
    By caitlyn.wright in forum Excel General
    Replies: 3
    Last Post: 04-18-2013, 06:19 PM
  5. [SOLVED] Convert data in multiple columns to single column
    By rkoffy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-07-2012, 08:03 AM
  6. To convert data in multiple sets of columns to multiple rows
    By Dhanya_nair in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2012, 02:49 PM
  7. Convert 1 row of data into Multiple columns
    By Mohoney in forum Excel General
    Replies: 1
    Last Post: 08-25-2005, 08:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1