Can I "subtotal" with an arbitary function, e.g., string concatenate?

I'd like to produce a "subtotal" of a table where the subtotal function is string concat instead of some numeric function (count, sum, average).

For example, consider this table:

enter image description here

I want the following result:

enter image description here

To me, this seems like "concat" (or "join") lifted over subtotaling. But I don't think Excel really understands functional programming (no matter what some people have claimed). So how can I do this (especially, how can I do this taking advantage of the Subtotal menu item that inserts all the subtotaling formulas automatically, even if I have to subsequently edit the formulas to get what I want to work).

And, in fact, Excel is very powerful with oodles of features. So can I achieve this in some other way besides subtotaling? (I would prefer non-scripting solutions.)

And, also, Excel isn't the only tool in the toolbox. Suppose I had this table in a CSV file. Is there a way to do this with standard Unix utilities (e.g., cut? Presumably awk could handle it, how would that look)?


This may not be the most elegant solution but try this, based on the fact that Col1 is guaranteed to be sorted:

  1. Add a column (C) to hold the cumulative concatenations of Col2 values. The formula for cell C2 is =IF(A2=A1, CONCATENATE(C1, ",", B2), B2) and you can autofill this for the rest of the cells.

  2. Add a column (D) to flag the rows holding the maximum (longest) concatenation, meaning the last row of each value in Col1. The formula for cell D2 is =IF(A2<>A3, TRUE, FALSE) and you can autfill the rest of the cells.

    The table will look like this:

    enter image description here

  3. Filter the table by TRUE values in column D:

    enter image description here

  4. You can now hide columns B and D:

    enter image description here