0
votes

I am writing a query function that I would like sorted. I have this figured out. What I cannot solve is attempting to insert 2 blank rows between the sorted results. Is this at all possible? Here is my query as it currently stands. Works perfectly as written. Just would like to have a 2 row gap between results.

Thank you.

=query('Form Responses 1'!A:CM,"Select B,C,D,I,L,AU,AX Where K = '"&Titles!B2&"' OR AW = '"&Titles!B2&"'Order by K,AW",0)

enter image description here

3

3 Answers

0
votes

Since you've clarified your question to say that you want two blank rows, only to be added at a specific point in your query results, I've created another answer. But you haven't answered my question about what criteria you have for deciding where to insert these two lines, so I've made an assumption based on your data. This formula should be easily adapted if you have some other criteria for where to insert the blank lines. See my added tab HelpGK in yur sample sheet.

Try this formula, where you have your query:

={query('Data Sheet'!A:J,"Select B,C,D,E,F,H,I Where E=''  and (G = 'ABC' OR J = 'ABC') Order by J,G",0);
  {"","","","","","",""};
  {"","","","","","",""};
  query('Data Sheet'!A:J,"Select B,C,D,E,F,H,I Where E<>'' and (G = 'ABC' OR J = 'ABC') Order by J,G",0)}

Note that I don't believe your exact Desired Result can be obtained from your Data sheet. You are missing data rows. But this formula produces the result in the screenshot you provided.

enter image description here

0
votes

EDIT: Just realised that I created an answer for a single column of data. Please share a sample sheet since this is not your case.

You can try this formula, but you'll need to replace this text "A4:A8" with your exact query:

=ArrayFormula(flatten(split(A4:A8 & "♥ ♥ ","♥",0,0)))

Note that the column with the "~" values in the blank cells is just to demonstrate what is happening.

If you had provided a sample sheet, with sample data, it would have been easier.

Let me know if this works for you. If not, please provide a sample sheet, with sample data, and let us know what else you need.

Be aware that the you can't put any values into the two inserted rows of blank cells, or the arrayformula will fail. But if you are planning to save the results of this as values, then pasted into place, then you could overwrite the blank cells, if desired.

Also be aware that FLATTEN is an undocumented function, and may possibly be removed from Sheets. If this is for a critical application, and alternative formula can be provided. Let us know if that is a concern.

enter image description here

0
votes

I will delete my earlier answer, which mistakenly focused on a one column result.

This messy formula seems to handle multiple columns. If it works for you, I'll see if I can simplify it or clean it up. I can also provide details of the steps it is doing, if necessary. Replace the text "A4:C8" in this formula with the range where your query result currently exists. Once you've tested that, you can replace the text "A4:C8" with your actual query statement, to have everything done in one formula, if you want.

=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(SPLIT(FLATTEN(ARRAYFORMULA(SPLIT(TRANSPOSE(ARRAYFORMULA(QUERY(TRANSPOSE(ARRAYFORMULA(SUBSTITUTE(A4:C8," ","♥"))),,99^99)&"♦~♦~")),"♦",1,0)))," ",1,0),"~",""),"♥"," "))

Please let me know if this works for you. If you have any issues, please share a sample sheet, with only sample data, and clarify what isn't working as you expect.

enter image description here