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.
Related
At the end of the day, in my Google Sheet I'm trying to filter a large data set by multiple criteria and sum a certain column. I have a mostly working formula but I'm running into a problem.
Here is an example that works:
=sum(INDEX(FILTER('Invoice Data'!H3:P,
'Invoice Data'!N3:N>=DATE(2022,1,1),
('Invoice Data'!H3:H="Arc")+('Invoice Data'!H3:H="Technical Products")
),0,9))
The ()+() in the second criteria works well as an OR condition. However, I want that criteria to be dynamic based on other information. So I've created the following formula that generates a text string as follows:
="('Invoice Data'!H3:H="&CHAR(34)&join(CHAR(34)&")+('Invoice Data'!H3:H="&CHAR(34),FILTER('Dropdown Menus'!D2:D34, A2='Dropdown Menus'!C2:C34))&CHAR(34)&")"
This successfully generates the text "('Invoice Data'!H3:H="Arc")+('Invoice Data'!H3:H="Technical Products")".
The problem is, when I put it into the original formula, it doesn't work.
=sum(INDEX(FILTER('Invoice Data'!H3:P,
'Invoice Data'!N3:N>=DATE(2022,1,1),
TO_TEXT("('Invoice Data'!H3:H="&CHAR(34)&join(CHAR(34)&")+('Invoice Data'!H3:H="&CHAR(34),FILTER('Dropdown Menus'!D2:D34, A2='Dropdown Menus'!C2:C34))&CHAR(34)&")")
),0,9))
I get the following error:
FILTER has mismatched range sizes. Expected row count: 27436. column count: 1. Actual row count: 1, column count: 1.
Any thoughts on what might be happening? I try to use "Indirect()" to have it be a cell reference, but that didn't work either.
You cannot make a text string become an executable formula that way.
What you can do is use the query() function and build the query statement dynamically.
For easier debugging, put the formula that builds the query statement text string in a cell of its own, and refer to that cell in the query(), like this:
=query('Invoice Data'!H3:P, S2, 0)
...where cell S2 contains your query statement.
instead of your OR try:
=SUM(INDEX(FILTER('Invoice Data'!H3:P,
'Invoice Data'!N3:N>=DATE(2022,1,1), REGEXMATCH(
'Invoice Data'!H3:H, "(?i)Arc|Technical Products")),,9))
where
"(?i)Arc|Technical Products"
can be dynamically referred as:
"(?i)"&TEXTJOIN("|", 1, FILTER('Dropdown Menus'!D2:D34, A2='Dropdown Menus'!C2:C34))
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.
Hello I would like to check for duplicate rows, not just a cell, in google sheets, i would like to apply this formula in conditional formatting so it would highlight the cell
Here is a sample of what i want to catch
I would like to catch a duplicate row,group,or pair of cells in exact order. Can anybody help me with the formula?
I tried searching and there seems to be no article about it yet, I also tried using countif on both rows and multiply them, but that does not solve it being a pair.
Let's say you have the following data:
https://ibb.co/sFhjN34
First, range select A1:B1001.
Then, paste the following formula in the custom formula bar.
=AND(A1<>"",COUNTIF(ARRAYFORMULA($A:$A&$B:$B),index(ARRAYFORMULA($A:$A&$B:$B),ROW($A1),))>1)
Explaination:
ARRAYFORMULA($A:$A&$B:$B)
This is creating a virtual array which concat two columns A & B.
E.g. juice crackers -> juicecrackers
index(ARRAYFORMULA($A:$A&$B:$B),ROW($A1),)
Since conditional formating will loop through all rows given the starting range you specify earlier (A1:B1001), this part is trying to loop through ROW($A_) such that index(ARRAYFORMULA($A:$A&$B:$B),ROW($A_),) will return the combined word.
COUNTIF(ARRAYFORMULA($A:$A&$B:$B),index(ARRAYFORMULA($A:$A&$B:$B),ROW($A1),))>1)
Count every combined word that it specified in this array ARRAYFORMULA($A:$A&$B:$B)
If it countup more than 1, it means duplicated.
A1<>"" For those blank cells, we ignore it.
Combine the two conditions. AND(A1<>"",COUNTIF(ARRAYFORMULA($A:$A&$B:$B) ....)
It's not quite as perfect as you'd like, but I think this is a start:
=AND($A1=$A2,$B1=$B2)
This doesn't highlight the last row of any matches it finds, but it might be serviceable for what you want (ex. if Row 1 through Row 3 match, it will only highlight Row 1 and Row 2).
Just change the columns to match the two you're working with, and then if you want it to highlight the entire row, change the Apply to range to A1:Z or however many columns you have.
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 ?
I am trying to use the INDEX() formula inside an ARRAYFORMULA(). As a simple (non-sense) example, with 4 elements in column A, I expected that the following array formula entered in B1 would display all four elements from A in column B:
=ARRAYFORMULA(INDEX($A$1:$A$4,ROW($A$1:$A$4)))
However, this only fills field B1 with a the value found in A1.
When I enter
=ARRAYFORMULA(ROW($A$1:$A$4))
in B1, then I do see all numbers 1 to 4 appear in column B. Why does my first array formula not expand similar like the second one does?
The INDEX function is one that does not support "iteration" over an array if an array is used as one of its arguments. There is no documentation of this that I know of; it simply is what it is. So the second argument will always default to the first element of the array, which is ROW(A1).
One clumsy workaround to achieve what you require relies on a second adjacent column existing next to the source data* (although it is unimportant what values are actually in that second column):
=ArrayFormula(HLOOKUP(IF(ROW($A$1:$A$4);$A$1);$A$1:$B$4;ROW($A$1:$A$4);0))
or indeed something like:
=ArrayFormula(HLOOKUP(IF({3;2;4;1};$A$1);$A$1:$B$4;{3;2;4;1};0))
edit 2015-06-09
* This is no longer a requirement in the newest version of Sheets; the second argument in the HLOOKUP can just be $A$1:$A$4.
Here is a tip for using vlookup with an array, so that even if the columns are moved later on the formula will still work correctly....
In general, configure the vlookup so that it's reading only 2 columns and returning the second. This can be done by inputting only the 2 columns required, rather than a range and column index.
Example:
Replace the following formula which would fail if columns are moved
=arrayformula( vlookup(C:C, booking!$A:$E ,5 ,false) )
with this formula which will continue to work even if columns are moved
=arrayformula( vlookup(C:C, {booking!$A:$A,booking!$E:$E} ,2 ,false) )
Note, you can also simulate the index function using vlookup.
Example:
Column R:R contains the row index numbers for looking up data in column booking!$A:$A
=arrayformula(vlookup(R:R ,arrayformula({row(booking!$A:$A), booking!$A:$A}),2 , false))
It's a nested array, so it can be helpful to test in stages, eg just the inner part for one example, eg return entry in row 10:
=vlookup(10 ,arrayformula({row(booking!$A:$A), booking!$A:$A}),2 , false)