I'd like to transpose a data that is in 2 columns (A:B). for example in below input, values A,B,C and D in column A appears 3 times each of them.
With this input (input 1) I use this formula and get the transposition correctly like the image below:
=INDEX($B$1:$B$12,4*ROWS(D$2:D2)+COLUMNS($D2:D2)-4)
INPUT1
+---+----+
| A | 2 |
+---+----+
| B | 3 |
+---+----+
| C | 4 |
+---+----+
| D | 1 |
+---+----+
| A | 6 |
+---+----+
| B | 12 |
+---+----+
| C | 4 |
+---+----+
| D | 76 |
+---+----+
| A | 1 |
+---+----+
| B | 2 |
+---+----+
| C | 37 |
+---+----+
| D | 9 |
+---+----+
But if input change (input2) in such way that A, B appears less times than C and D, my output is incorrect.
INPUT2
+---+----+
| A | 2 |
+---+----+
| B | 3 |
+---+----+
| C | 4 |
+---+----+
| D | 1 |
+---+----+
| C | 4 |
+---+----+
| D | 76 |
+---+----+
| C | 37 |
+---+----+
| D | 9 |
+---+----+
| A | 47 |
+---+----+
| B | 2 |
+---+----+
| C | 37 |
+---+----+
| D | 9 |
+---+----+
I show in image below the incorrect output and expected output.

Thanks in advance for any help.


