Nikki Luzader
Nikki Luzader

Reputation: 111

Is there a formula to put strings before and between multiple queries?

I have multiple queries that I am combining, but I need to put a string in between each query. I have written the formula to combine multiple queries, but cannot figure out how to put strings around the queries. The desired result on the right on the image:

example data with desired result

I have tried concatenation, but it puts my entire query into one cell. I have tried curly braces, but I get a formula parse error.

Example 1: working query without trying to include strings (test result in image):

={QUERY(F6:H17,"select G, F where H = 1");QUERY(F6:H17,"select G, F where H = 2");QUERY(F6:H17,"select G, F where H = 3");QUERY(F6:H17,"select G, F where H = 4")}

Example 2: concatenation that results in query being in one cell:

=CONCATENATE("box 1",{QUERY(F6:H17,"select G, F where H = 1");QUERY(F6:H17,"select G, F where H = 2");QUERY(F6:H17,"select G, F where H = 3");QUERY(F6:H17,"select G, F where H = 4")})

Example 3: using curly braces to combine string with query - formula parse error:

={"box 1",QUERY(F6:H17,"select G, F where H = 1");"box 2; "QUERY(F6:H17,"select G, F where H = 2");"box 3"; QUERY(F6:H17,"select G, F where H = 3");"box 4;"QUERY(F6:H17,"select G, F where H = 4")}}

I expected the strings to be placed before and after the queries as coded, but I got many different kinds of results.

Upvotes: 0

Views: 68

Answers (1)

pnuts
pnuts

Reputation: 59475

I think your first attempt was extremely close, just lacked labels:

={QUERY(F6:H17,"select G, F where H = 1 label G 'box 1'");QUERY(F6:H17,"select G, F where H = 2 label G 'box 2'");QUERY(F6:H17,"select G, F where H = 3 label G 'box 3'");QUERY(F6:H17,"select G, F where H = 4 label G 'box 4'")} 

Upvotes: 1

Related Questions