Google-sheets – Aggregate data to show text in one cell
google sheetsgoogle-sheets-query
I need to put together multiple entries into one where the results is text and has to be in one cell.
From this
to this
Best Answer
There is an excellent precedent on StackOverflow for this question - though I can't locate it just as the moment. This solution is based on How to do a "group concat" in an ARRAYFORMULA? in the Google support form.
Let's assume that your raw data is in Columns A and B, and the output will be in Columns C and D.
Insert this formula in Cell C1. =Arrayformula(unique({A1:A, substitute(Trim(transpose(query(if(transpose(A1:A)=A1:A,B1:B&Char(10),),,9^99))),char(10),",")}))
One can't have both data and a formula in the same cell. If you want B4 to change in response to changes elsewhere (and don't want to write a script), then B4 must contain a formula. Then the data (such as "4, 7, 8, 5H") must be elsewhere. In my example, the data is in A4 but it could be any cell. Here is the formula for B4:
iferror(join("|", filter(E4:H4, len(E4:H4))), "") joins nonempty cells in the range E4:H4 into a regular expression such as 7|abc|5H
The regex is wrapped in word boundaries: \b(7|abc|5H)\b, so that 7 does not get removed from 7H, for example.
It is made case-insensitive with the flag (?i), so that 2h is treated the same as 2H.
regexreplace replaces the above with empty strings
The split-join operation takes care of empty places left after replacement. For example, if regexreplace produced 4, 7, , 5H then split-join will make it 4, 7, 5H.
If a user double-clicks in a cell, what they see is their input into that cell. In the situation described, that input will be a formula, for example =C4, not the output of that formula such as "0001-190716-AM-ABERD".
To copy the output of a formula, select the cell by clicking on it once, then copy. When pasting the result in another place in the spreadsheet, you have two options:
ordinary paste Ctrl-V will copy the formula, adjusting its cell references
value-only paste Ctrl-Shift-V will copy only the output of the formula, as plain text.
Best Answer
There is an excellent precedent on StackOverflow for this question - though I can't locate it just as the moment. This solution is based on How to do a "group concat" in an ARRAYFORMULA? in the Google support form.
Let's assume that your raw data is in Columns A and B, and the output will be in Columns C and D.
Insert this formula in Cell C1.
=Arrayformula(unique({A1:A, substitute(Trim(transpose(query(if(transpose(A1:A)=A1:A,B1:B&Char(10),),,9^99))),char(10),",")}))
BEFORE - raw data
AFTER - additional data