Search code examples
arraysgoogle-sheetsgoogle-sheets-formulatextjoin

Combining rows and columns of text using Sheets Queries


I'm trying to get to an array function that will select multiple rows and columns of data and present the data cleanly in a single cell. The data in the orange headed block has multiple rows (speakers) for each ID (sessions). The data in the blue block is the unique list of IDs (sessions) where I'm trying to get a formatted output. The ideal output would be (name) - (title) separated by cf/lf so multiple speakers will stack neatly in the same cell.

This gives an imperfect result with everything separated by dashes:

=TEXTJOIN(" - ",1,QUERY(A2:D17,"select B,C where A matches '"&F4&"' and D = 'T1'",0))

This should be closer to what I'm looking for but spits out a row mismatch error:

=QUERY({A:A,B:B&" - "&C:C&char(10),D:D},"select Col2 where Col1 matches '"&F4&"' and Col3 ='T1'",0)

And of course neither of these does this as an array and I'm trying to avoid having to maintain the sheet as sessions and speakers are added. I struggle with the intricacies of the query function so any help/instruction you can give would be very much appreciated!

example

Example Data


Solution

  • try:

    =ARRAYFORMULA(TEXTJOIN(CHAR(10), 1, QUERY({A:A, B:B&" - "&C:C, D:D},
     "select Col2
      where Col1 matches '"&F4&"' 
        and Col3 ='T1'", 0)))