+ Reply to Thread
Results 1 to 6 of 6

Convert columns to rows, keeping first column identifier

  1. #1
    Registered User
    Join Date
    12-16-2021
    Location
    Adelaide, Australia
    MS-Off Ver
    Office 365
    Posts
    4

    Convert columns to rows, keeping first column identifier

    Hi all

    I have a table with employee identifier data in the first two columns, running down in rows and strings of data (date and times) in the remaining columns. What I need to do is to have the date and time in and date and time out in rows for each employee, but keeping the identifier in the first column. For example:

    Current view:

    Name ID Date/Time1(in) Date/Time1(out) Date/Time2(in) Date/Time2(out) Date/Time3(in) Date/Time3(out)

    What I need is:

    Name ID Date/Time1(in) Date/Time(out)
    Name ID Date/Time2(in) Date/Time(out)
    Name ID Date/Time3(in) Date/Time(out)
    Etc

    i've attached a sample workbook. Any help in this is greatly appreciated

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    03-18-2014
    Location
    Singapore
    MS-Off Ver
    Excel 2016 / 2019
    Posts
    251

    Re: Convert columns to rows, keeping first column identifier

    Hi,

    Easier way is to use power query editor, bring in your cross table (with all your multiple ins and outs), build a query (one off) by unpivotting into a flat table,
    standardize all the in and out so that can fit into the pivot column In and Out, Values will be the date and time

    See Attached tab 2 "Output (Power Query)" for the results

    The M code (mainly using the UI of Power Query Editor

    Please Login or Register  to view this content.
    Christopher Yap

  3. #3
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,368

    Re: Convert columns to rows, keeping first column identifier

    Option using formula and using helper table:
    1. Put this on P2 and copied down and copied cross until comn Q =IFERROR(INDEX(A$2:A$4,AGGREGATE(15,6,(ROW($A$2:$A$4)-MIN(ROW($A$2:$A$4))+1)/($A$2:$A$4<>""),ROW(A1))),"")
    2. Put this on R2 and copied down =SUMPRODUCT(($A$2:$A$4=P2)*(ISNUMBER(SEARCH("In",$C$1:$N$1)*($C$2:$N$4<>""))))

    And fo results table,
    1. Put this on A10 and copied down and cross until column B =LOOKUP(ROW(A1),SUMIF(OFFSET($R$1,,,ROW($1:$99),),"<>")+1,P$2:P$99)
    2. Put this on C10 and press all together CTRL+SHIFT+ENTER button because this an array formula then copied down and cross to column D
    =IFERROR(INDEX($C$2:$N$4,SMALL(IF(($A$2:$A$4=$A10)*(ISNUMBER(SEARCH(C$9,$C$1:$N$1))),MATCH(ROW($C$2:$N$4),ROW($C$2:$N$4)),""),COUNTIF($A$10:$A10,$A10)),1*(SMALL(IF(($A$2:$A$4=$A10)*(ISNUMBER(SEARCH(C$9,$C$1:$N$1))),MATCH(ROW($C$2:$N$4),ROW($C$2:$N$4))+1*MATCH(COLUMN($C$2:$N$4),COLUMN($C$2:$N$4)),""),COUNTIF($A$10:$A10,$A10))-SMALL(IF(($A$2:$A$4=$A10)*(ISNUMBER(SEARCH(C$9,$C$1:$N$1))),MATCH(ROW($C$2:$N$4),ROW($C$2:$N$4)),""),COUNTIF($A$10:$A10,$A10)))),"")
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-16-2021
    Location
    Adelaide, Australia
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Convert columns to rows, keeping first column identifier

    thank you both for your responses. I'll give them a shot!

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Convert columns to rows, keeping first column identifier

    As you have xl365, another option
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    12-09-2014
    Location
    Trakai, Lithuania
    MS-Off Ver
    2016
    Posts
    1,293

    Re: Convert columns to rows, keeping first column identifier

    Formulas
    Name and ID
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    In
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Out
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. [SOLVED] Remain 1 columns and convert 2 column to many Rows
    By mohammaduir in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-07-2020, 02:11 PM
  2. [SOLVED] sorting rows with unique identifier and then duplicate identifier
    By Roshan.Shakya in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-13-2019, 06:02 AM
  3. Transpose Columns into Rows based on Unique Identifier for n columns
    By bhavt010785 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2017, 11:55 AM
  4. Replies: 1
    Last Post: 01-29-2015, 04:08 PM
  5. [SOLVED] Columns to rows, keeping column A and filling down
    By Cakin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2014, 02:32 PM
  6. Need VBA to Convert 1 Column with a ton of data into several rows and columns
    By shirley16 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2014, 03:47 PM
  7. Merging Rows & Columns on Unique Identifier
    By oxv in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-20-2012, 06:52 PM

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