Share via

Excel - Consolidate IDs and display data horizontally

Joe Daniel 0 Reputation points
2026-03-10T15:49:54.0166667+00:00

I have a dataset that is not useful to me in its current format, and I lack the Excel knowledge to automate what I'd like to accomplish.

The current data set contains:

  • Column A: An ID number.

Columns B, C, and D: A single row of data that corresponds to the unique ID in Column A.

When columns B, C, and D contain different information for a specific ID number in Column A, a new row is created. See first screenshot at bottom of this post for a visual.

Ideal state:

  • Column A: ID numbers to be consolidated, so there is only one row per ID number.

Columns B, C, and D: For each ID number, this information is displayed horizontally in a single row next to the computer ID. See second screenshot at the bottom of this post for a visual.

The really tricky part is that not all computer IDs have the same number of entries. For example: One computer ID may have four associated entries, where another may have eight associated entries.

CURRENT STATE

User's image

IDEAL STATE

User's image

Any help is very much appreciated! I tried to ask AI to do this and... well, I wouldn't be asking this question here if it went well. Ha!

Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. IlirU 1,936 Reputation points Volunteer Moderator
    2026-03-11T10:57:32.9833333+00:00

    User's image

    Hi @ Joe Daniel,

    See if the formula below helps you achieve the result you want.

    Hope this helps.

    IlirU

    =LET(
      gb, HSTACK(BYROW(A2:B5, ARRAYTOTEXT), BYROW(C2:E5, ARRAYTOTEXT)),
       d, IFNA(TEXTSPLIT(TEXTJOIN(";",, BYROW(GROUPBY(TAKE(gb,, 1), DROP(gb,, 1),
          ARRAYTOTEXT,, 0), ARRAYTOTEXT)), ", ", ";"), ""),
          IF(ISNUMBER(--d), --d, d)
    )
    
    0 comments No comments

  2. Ashish Mathur 101.7K Reputation points Volunteer Moderator
    2026-03-10T23:41:11.5833333+00:00

    Hi,

    This M code in PQ works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Grouped Rows" = Table.Group(Source, {"ID"}, {{"Count", each Table.AddIndexColumn(_,"Index",1,1)}}),
        #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Source", "#", "MD", "Index"}, {"Source", "#", "MD", "Index"}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Expanded Count", {"ID", "Index"}, "Attribute", "Value"),
        #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Index", type text}}, "en-IN"),{"Attribute", "Index"},Combiner.CombineTextByDelimiter("_", QuoteStyle.None),"Merged"),
        #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value")
    in
        #"Pivoted Column"
    

    User's image

    0 comments No comments

  3. Hendrix-C 12,120 Reputation points Microsoft External Staff Moderator
    2026-03-10T17:19:44.46+00:00

    Hi @Joe Daniel,

    Thank you for posting your question in the Microsoft Q&A forum.

    According to your concern, you can try using Power Query to achieve your expected results since Power Query can help you update automatically if new rows are added into the data table:

    • First, I imported your data like this. Then select any cell in the range > press Ctrl + T to convert to a table and also check the box "My table has headers" > OK

    User's image

    • Then click anywhere inside the table > go to Data tab > Get Data > From other sources > From Table Range > you will see Power Query opening
    • In the Power Query editor, click the ID column > Transform > Data Type > Text (since your ID data is more than 15 digits, so you need to keep it as Text so Excel doesn't round it)

    User's image

    • Next step, go to Home > Group By > set Group by: ID > New columns name: Allrows > Operation: All Rows > OK > you will have two columns left: ID and Allrows

    User's image

    • Now go to Add Column tab > Custom Column > name the column Groupedwithindex > paste this formula Table.AddIndexColumn([Allrows], "Entry", 1, 1, Int64.Type) > OK

    User's image

    • Now you will have three columns ID, Allrows and Groupwithindex. Right click the Allrows column and remove it
    • Click the expand icon on Groupedwithindex and select these columns to expand and also uncheck "use orginal column.." > OK

    User's image

    • Hold Shift and select three columns SOURCE, # and MD then go to Transform > Unpivot Columns > it will become two columns like below (Attribute and Value)

    User's image

    • Then go back to Add Column > Custom Column > name the column PivotKey > paste this formula [Attribute] & "_" & Text.From([Entry]) > OK

    User's image

    • Now you will see five columns ID, Entry, Attribute, Value and PivotKey. Right click and remove two columns Entry and Attribute
    • Last step, select the PivotKey column > Transform tab > Pivot Column > Set the dialog as same as below and then OK

    User's image

    • Now go to Home tab > Close and Load > you will have the result as your ideal state.

    User's image

    Whenever any new data added, you just need to click inside the range > Query tab > Refresh and new data will be updated into your table.

    Hope this information will help. Please follow these steps and let me know if it works for you. If you have any questions or need further assistance, please feel free to share them in the comments so I can continue to support you.

    Thank you for your patience and understanding. I'm looking forward to your reply.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  4. Q&A Assist
    2026-03-10T15:50:16.54+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Use a formula-based “unpivot → re‑pivot” approach so each ID appears once and its related rows are spread horizontally.

    Assume the current data is in Sheet1 with headers in row 1:

    • A: ID
    • B: SOURCE
    • C: #
    • D: MD

    1. Create a helper column to count entries per ID

    In E2 enter and copy down:

    =COUNTIF($A$2:A2,A2)
    

    This gives 1 for the first row of an ID, 2 for the second row of the same ID, etc.

    2. Build the horizontal layout

    On a new sheet (or to the right of the data), create the output table.

    In G1 put ID. In H1, I1, J1, K1, L1, M1, etc., put the headers you want, for example:

    SOURCE_1 #_1 MD_1 SOURCE_2 #_2 MD_2 SOURCE_3 #_3 MD_3 ...

    Unique IDs

    In G2 enter:

    =IFERROR(INDEX($A$2:$A$1000, MATCH(0, COUNTIF($G$1:G1, $A$2:$A$1000), 0)), "")
    

    Confirm as an array formula if required by the Excel version (Ctrl+Shift+Enter), then copy down until blanks appear. This lists each ID once.

    3. Pull each nth record for each ID into columns

    For SOURCE_1 (H2):

    =IFERROR(INDEX($B$2:$B$1000, MATCH(1, ($A$2:$A$1000=$G2)*($E$2:$E$1000=1), 0)), "")
    

    For #_1 (I2):

    =IFERROR(INDEX($C$2:$C$1000, MATCH(1, ($A$2:$A$1000=$G2)*($E$2:$E$1000=1), 0)), "")
    

    For MD_1 (J2):

    =IFERROR(INDEX($D$2:$D$1000, MATCH(1, ($A$2:$A$1000=$G2)*($E$2:$E$1000=1), 0)), "")
    

    Adjust the =1 to =2 for SOURCE_2/#_2/MD_2, to =3 for SOURCE_3/#_3/MD_3, and so on. Copy these formulas down for all IDs.

    Each ID now occupies a single row, and its 1st, 2nd, 3rd, … related records are laid out horizontally. IDs with fewer entries simply leave later groups of columns blank.

    If the maximum number of entries per ID is large, the same pattern can be extended as far as needed.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.