0

Suppose I have this table:

| Name   | Amount | Category |
| name_1 | 10     | A        |
| name_2 | 2      | B        |
| name_3 | 3      | B        |
| name_4 | 6      | C        |

Thanks to this answer, I know how to write a query that groups the rows by category, and gives me sum of Amount by category, like this:

=QUERY(A2:C5,"select C, sum(B) group by C order by sum(B)")

enter image description here

My question is: how do I add a third row to my query, such that it lists the Name of every row in that group (possibly, but not necessarily, comma-separated)?

In other words, I'd like the result to look like this:

|   | sum | items          |
| B | 5   | name_2, name_3 |
| C | 6   | name_1         |
| A | 10  | name_4         |
dcastro
  • 103
  • 3

1 Answers1

1

Use filter(). Put this formula in cell C11:

=iferror( textjoin( ", ", true, filter(A$2:A$5, C$2:C$5 = A11) ) )

...and copy the formula cell down.

doubleunary
  • 16,056
  • 9
  • 24
  • 59