Muhammad Vakili
Muhammad Vakili

Reputation: 708

Concatenate range with filter

I have a table that contains Codes and their related Value

+------+-------+
| Code | Value |
+------+-------+
|    1 | val1  |
|    2 | val1  |
|    3 | val1  |
|    4 | val2  |
|    5 | val2  |
|    6 | val1  |
|    7 | val3  |
|    8 | val3  |
+------+-------+

Now, I wanna reverse it using formula and display all codes in front of specific value and concatenate all codes in one cell like this :

+-------+---------+
| Value |  Codes  |
+-------+---------+
| val1  | 1,2,3,6 |
| val2  |     4,5 |
| val3  |     7,8 |
+-------+---------+

I don't want to do this using pivot table, I need a formula.

Upvotes: 1

Views: 41

Answers (1)

Imran Malek
Imran Malek

Reputation: 1719

Sort your data based on values first.

Write this formula in cell C2 and drag down.

=IF(B2<>B1,A2,C1 & ", " & A2)

Write this formula in cell D2 and drag down.

=B2=B3

You should then be able to see the result as below,

enter image description here

Now sort on False,

enter image description here

Upvotes: 1

Related Questions