Search code examples
google-sheetsgoogle-sheets-formulaspreadsheetarray-formulastextjoin

Arrayformula textjoin in another arrayformula wont work


Could someone help me with this formula:

arrayformula(TEXTJOIN(", ",TRUE,unique(IF(Sheet1!$A:$A=A2,Sheet1!$B:$B,""))))

So basically, I've got the name of Merchants in 'Sheet1'!$A:$A and the name of the Campaign Name Period they're working on in 'Sheet1'!$B:$B I want to generate the merged Campaign Name Period, I want to make this line above to work with another arrayformula so I don't have to copy this formula to all cells in the column, I've tried to make it like this.

arrayformula(arrayformula(TEXTJOIN(", ",TRUE,unique(IF('Sheet1!$A:$A=$A2:$A,Sheet1!$B:$B,"")))))

but still, it won't work, it gives me this "Error Array arguments to EQ are of different size."

Here's a link to the sample spreadsheet


Solution

  • Try something like

    =arrayformula(regexreplace({unique(Sheet1!A2:A), trim(transpose(query(if((transpose(unique(Sheet1!A2:A))=Sheet1!A2:A)*len(Sheet1!A2:A),Sheet1!B2:B&", ",),,50000)))},",$", ))
    

    Note that this formula will also create the unique merchant names.

    UPDATE:

    Using the new map() or byrow() functions it is now possible to skip the intermediate step of creating a unique list. Try

    =unique({Sheet1!A:A, map(Sheet1!A:A,  lambda( item, textjoin(", ", 1, unique(filter(Sheet1!B:B, Sheet1!A:A=item)))))})
    

    or

    =unique({Sheet1!A:A, map(Sheet1!A:A,  lambda( item, textjoin(", ", 1, unique(filter(Sheet1!B:B, Sheet1!A:A=item)))))})
    

    More info: MAP(), BYROW()