How to use IFERROR inside an array formula? - google-sheets

If any of the queries in an array formula do not have actual data to query in the range they are hitting they return #VALUE! and mousing over the array formula reveals an error. If I take those queries and wrap them in an IFERROR I get the same results.
If I take what I wrapped in an IFERROR and split it out into its own cell to validate the query it results in displaying the error clause which in this case is a 0.
Here is a link to an example sheet.
Sheet1 has sample data.
Sheet2 is intentionally blank to simulate the issue described above.
Sheet3 has three queries on it in various states. The top two are the array formulas I am attempting to work with. The bottom Query is the IFERROR split out into its own cell to show that the query does in fact work when separated from the rest of the sort(arrayformula(etc)).

Try combining both ranges (from both sheets) inside 1 query instead of using 2 queries, and wrap an IFERROR() around that single query:
=ARRAYFORMULA(IFERROR(QUERY({Sheet1!A1:I500; sheet2!A1:I500}, "Select * where Col7='no'", 0), 0))
See if that works for you ?

Related

Creating a recursive Formula in Google Sheets

So here's what I'm trying to do: I have a query formula on Sheet 3 that pulls data from Sheet 2, based on values from Sheet 1. Then I add a header/footer row before/after the data. What I want to do is re-run that formula block for each row in Sheet 1 Column A that has data, but in each instance increase the value of the row by one, and stop when the rows are empty.
Can't just do it with a single query with grouping/ordering, because of the headers/footers.
So far, I've got this (just the first two cycles):
`={
{Sheet1!A3,"","","","","",""};
query(Sheet2!D:S, "select D,F,H,J,N,P,R where J contains '"&Sheet1!A3&"' order by F",0);
{"TOTAL","","","","","",Sheet1!B3};
{"","","","","","",""};
{Sheet1!A4,"","","","","",""};
query(Sheet2!D:S, "select D,F,H,J,N,P,R where J contains '"&Sheet1!A4&"' order by F",0); {"TOTAL","","","","","",Sheet1!B4}
}`
The result is this:
screenshot
It works great, but it'll be super tedious to repeat dozens of times.
This is pushing against the bounds of my formula knowledge, so I need someone to point me in the right direction. Is this handled with some sort of INDEX or VLOOKUP or ARRAY function? Or would it require a script?
Could you try with this REDUCE option and let me know if it returns your desired result?
=REDUCE({"","","","","","",""},SEQUENCE(COUNTA(Sheet1!A3:A)),LAMBDA(a,b,{a;
{INDEX(Sheet1!A3:A,b),"","","","","",""};
query(Sheet2!D:S, "select D,F,H,J,N,P,R where J contains '"&INDEX(Sheet1!A3:A,b)&"' order by F",0);
{"TOTAL","","","","","",INDEX(Sheet1!B3:B,b)}}))
You may change the first argument all those "","","" with the headers from your table. Let me know if it's useful

Display results from filter formula in one row?

I am using a filter formula to output multiple results based on a condition. Each result contains 4 columns of data, each result is in a new row. However, I would like all results to be output one after the other (i.e. in one row). The data of each result takes up 4 columns and in the fifth column, the new result starts with 4 columns.
This is how it looks now:
This is how it should look:
To get this dynamically, follow these steps.
1 - in the sheet where you want the results on cell A2 past this formula.
=TRANSPOSE(FLATTEN(QUERY(Data!A2:D," Select * where A is not null ")))
TRANSPOSE because FLATTEN formula outputs a column.
QUERY to remove blank rows.
FLATTEN to convert all values from one or more ranges into a single column.
2 - to make the header dynamic you need to paste this formula in resault sheet in cell A1.
=SPLIT(REPT(JOIN(";",Data!A1:D1)&";",COUNTA(Data!A2:A)),";")
JOIN the header with ; so you can split it with the SPLIT formula after repeating the header rang n time with the REPT formula, to handel how many times the header repeated just use COUNTA to count how many rows are there.
Input example:
Output example:
You first need to use Flatten() to make it a one dimensional array since the spreadsheet data is in a nested array no matter how many rows/columns you have.
Then from here you can just transpose the data so instead of the data going down the rows it will be transposed to go horizontally to the columns.
Try:
=TRANSPOSE(FLATTEN(A2:D))
To combine it with your formula just replace the Range "A2:D" with your current formula.
Result:
References:
Transpose
Flatten

Unique QUERY based on IFS, AND formula in Google Sheets

I have 4 different queries that pull different columns of data.
I would like to create an IFS, AND formula on some checkboxes. Based on what checkbox is clicked, I would like it to execute the specific query.
I am getting the error:
IFS has mismatched range sizes. Expected row count: 1. column count: 1. Actual row count: 20, column count: 2.
Here is a working example of my formula (IFS, AND, without QUERY)
=IFS(
AND(E3=TRUE,F3=TRUE),"Both boxes are checked. (TRUE/TRUE)",
AND(E3=FALSE,F3=FALSE),"Both boxes are unchecked. (FALSE/FALSE)",
AND(E3=TRUE,F3=FALSE),"First box is checked. (TRUE/FALSE)",
AND(E3=FALSE,F3=TRUE),"Second box is checked. (FALSE/TRUE)"
)
Here is the non-working version of my formula (IFS, AND, with QUERY)
=IFS(
AND(E3=TRUE,F3=TRUE),QUERY(J1:K),
AND(E3=FALSE,F3=FALSE),QUERY(L1:M),
AND(E3=TRUE,F3=FALSE),QUERY(N1:O),
AND(E3=FALSE,F3=TRUE),QUERY(P1:Q)
)
Why is this formula breaking when I introduce query?
Click Here - to view my Google Sheet.
IFS within an ArrayFormula does not behave as nested IFs do in an ArrayFormula
You will have to use nested IFs for your formula.
Try the following
=ArrayFormula(IF(AND(E3=true,F3=true),J3:K,
IF(AND(E3=FALSE,F3=FALSE),L3:M,
IF(AND(E3=true,F3=FALSE),N3:O,
IF(AND(E3=FALSE,F3=true),P3:Q)))))
You also notice that the QUERY function is not needed because you do not actually use it.

Only odd columns in arrayformula on google sheets

I have multiple columns that I need to stack into one column. But I only want to have odd columns in the list.
This is the formula I'm working with, which works to get all in one column. But not just odd ones
=TRANSPOSE(SPLIT(ARRAYFORMULA(CONCATENATE(TRANSPOSE(FILTER(A:D,A:A>0)&""))),""))
https://docs.google.com/spreadsheets/d/1yAPw13VE7uclP0ILzUYxZBgLGid9PrZXpWmhuEgi1S0/edit?usp=sharing
Appreciate the help.
You can also use QUERY with 'skipping 2' option. This takes only every 2nd row so to make it useful you have to transpose your range first. Then you FLATTEN your columns.
As you can see, there's a different order of values:
=flatten(query(transpose(A1:D4),"select * skipping 2 "))
This should do it:
=QUERY(FLATTEN(FILTER(A:D,ISODD(COLUMN(A:D)))),"Select * Where Col1 Is Not Null")
FILTER filters in all cells from odd columns.
FLATTEN makes one column of all of the FILTERed results.
QUERY weeds out blank rows.

Google Sheets VLOOKUP across Mismatched Ranges in Multiple Sheets

This formula should look up in the A column of multiple sheets and when the match is found (in this case there are not duplicates in any A column of the different sheets), it gives back the value found in the cell next on the right to the match.
=ArrayFormula(IF(LEN(B5),VLOOKUP(B5,{SHEET1!$A$3:$B,SHEET2!$A$15:$B},2,FALSE),""))
But it gives a mismatch error and even if I make the ranges the same length the value in B5 is searched only into the first sheet of the range, in this case SHEET1!$A$3:$B.
Is is possible to make the formula work with ranges of different length from multiple sheets?
always when you construct the virtual array with array brackets {} both sides needs to be of the same size.
={A1:A10, B1,B10}
or:
={A1:C10; D1:F10}
in your case, the array literal error comes from mismatched rows when you use "infinite" rows by not specifying the end row. eg your sheet1 has more or fewer rows then your sheet2
=INDEX(IF(LEN(B5), VLOOKUP(B5, {SHEET1!A3:B; SHEET2!A15:B}, 2, 0), ))

Resources