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: