Search code examples
google-sheetsconcatenationgoogle-sheets-formulaarray-formulastextjoin

ArrayFormula with TEXTJOIN - Combine data of two columns on the same row/cell


I have one Google Sheet that contains ID-values, together with corresponding Names and Attack power. In another sheet, I want to combine Names and Attack power in the same cell using the ID as a reference - separated with row breaks.

Sheet1

Sheet1 looks like this:

| GROUP ID | NAME      | ATTACK POWER  |
|---------:|:----------|--------------:|
|      101 | guile     |           333 |
|----------|-----------|---------------|
|      101 | blanka    |            50 |
|----------|-----------|---------------|
|      101 | sagat     |           500 |
|----------|-----------|---------------|
|      207 | ruy       |           450 |
|----------|-----------|---------------|
|      207 | vega      |           150 |

Sheet2

Right now, I have created the following ArrayFormula that sort of does what I want.

In NAME-column: =ArrayFormula(TEXTJOIN(CHAR(10);1;REPT(Sheet1!B:C;1*(Sheet1!A:A=A2))))

Which returns the following result:

| GROUP ID | NAME                      |
|---------:|:--------------------------|
|      101 | guile                     |         
|          | 333                       |
|          | blanka                    |
|          | 50                        |
|          | sagat                     |
|          | 500                       |
|----------|---------------------------|
|      101 | ruy                       |
|          | 450                       |
|          | vega                      |
|          | 150                       |
|----------|---------------------------|

The problem is that I can't figure out how to get Name and Attack Power on the same line.

Tried combining with CONCATENATE: =CONCATENATE(ArrayFormula(TEXTJOIN(CHAR(10);1;REPT(Sheet1!B:B;1*(Sheet1!A:A=A2))));" (";ArrayFormula(TEXTJOIN(CHAR(10);1;REPT(Sheet1!C:C;1*(Sheet1!A:A=A2))));")") - but it's not quite right:

| GROUP ID | NAME                      |
|---------:|:--------------------------|
|      101 | guile                     |         
|          | blanka                    |
|          | sagat (333                |
|          | 50                        |
|          | 500)                      |
|----------|---------------------------|
|      101 | ruy                       |
|          | vega (450                 |
|          | 150)                      |
|----------|---------------------------|

I would instead the sheet to look like this:

| GROUP ID | NAME                      |
|---------:|:--------------------------|
|      101 | guile (333)               |         
|          | blanka (50)               |
|          | sagat (500)               |
|----------|---------------------------|
|      101 | ruy (450)                 |
|          | vega (150)                |
|----------|---------------------------|

Is this possible?


Solution

  • =ARRAYFORMULA(TEXTJOIN(CHAR(10), 1, 
     REPT(Sheet1!B:B&" ("&Sheet1!C:C&")", 1*(Sheet1!A:A=A4))))
    

    0