Google-sheets – How to modify this Google formula to filter out blank responses from Google Sheets

form-mulegoogle sheetsgoogle-sheets-addonsgoogle-sheets-custom-function

I have Google Sheets running the add-on Form Mule to automatically send emails with the responses to a Google Form. Using the following formula, I was able to get a nice HTML table to show up in the body of each email.

=RANGETOTABLE(FILTER(D:AH,A:A=A2),$D$1:$AH$1)

This returns a table that looks like this:

Blank cells and a single response cell

I want to try and filter the cells with nothing in them, out, so that only cells with values in them are returned.

Best Answer

You can include multiple conditions in a filter by using multiplication (which means logical AND). For example,

FILTER(D:AH, (A:A=A2) * LEN(E:E) * LEN(H:H))

requires A to be equal to A2 and E to be nonempty and H to be nonempty.

Conditions can also be combined using addition, which stands for logical OR:

FILTER(D:AH, (A:A=A2) * (LEN(E:E) + LEN(H:H)))

requires A to be equal to A2 and that either E or H be nonempty.

If you have a lot of columns (like D:AH), one of which must be nonempty, the formula will have to be somewhat long. Instead of adding lengths as above, one can use concatenation & to shorten it a bit:

FILTER(D:AH, (A:A=A2) * LEN(E:E & F:F & G:G & H:H & I:I & J:J & K:K & L:L & M:M & N:N & O:O & P:P & Q:Q & R:R & S:S & T:T & U:U & V:V & W:W & X:X & Y:Y & Z:Z & AA:AA & AB:AB & AC:AC & AD:AD & AE:AE & AF:AF & AG:AG & AH:AH))`

Long, but you only have to do it once.


By the way, I used a spreadsheet to generate the long string above, by making a column of letters (say, in A1:A30) and then using =join(" & ", arrayformula(A1:A30 & ":" & A1:A30)))