Search code examples
google-sheetsgoogle-sheets-formulatransposearray-formulasgoogle-sheets-query

In Google Sheets, how can one aggregate values (MAX, MIN, AVERAGE) based on the result of splitting a string in a different column?


If I had a table with the following values, how can I generate the following table? The result table separates out each tag and calculates the number of rows with the tag mentioned (COUNT) and also the max value for a given tag.

    +-----+-------------+
    | VAL | TAGS        |
    +-----+-------------+
    |  4  | html, css   | 
    +-----+-------------+
    |  2  | js, ts      |
    +-----+-------------+
    |  3  | js, css     |
    +-----+-------------+
    +------+-------+-------+
    | TAG  | COUNT |  MAX  |
    +------+-------+-------+
    | html |   1   |   4   |
    +------+-------+-------+
    | css  |   2   |   4   |
    +------+-------+-------+
    | js   |   2   |   3   |
    +------+-------+-------+
    | ts   |   1   |   2   |
    +------+-------+-------+

Solution

  • try:

    =ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
     IF(IFERROR(SPLIT(B3:B, ","))<>"", "♀"&A3:A&"♦"&SPLIT(
     SUBSTITUTE(B3:B, ", ", ","), ",")&"♦", )),,999^99)),,999^99), "♀")), "♦"), 
     "select Col2,count(Col1),avg(Col1),max(Col1),min(Col1) 
      group by Col2
      label Col2'tags'"))
    

    0

    0