Search code examples
if-statementgoogle-sheetsgoogle-sheets-formulaarray-formulasgoogle-sheets-query

How to Concatenate a Select with the query()?


I'm use the query function, and what I want is to combine columns A, B, and C into a string with hyphens separating them. i.e. "2-4-6".

A|B|C
-|-|-
2|4|6

How could I do this?

I've tried the following but it returns an error:

=query(raw!A1:C, "select 'A & '-' & B & '-' &C")

Solution

  • try:

    =ARRAYFORMULA(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(raw!A1:C),,999^99))), " ", "-"))
    

    0


    or use:

    =ARRAYFORMULA(raw!A:A&IF(raw!B:B="",,"-"&raw!B:B)&IF(raw!C:C="",,"-"&raw!C:C))