Using nested IF/AND statements in Sheets in a single cell - google-sheets

I'm trying to create a formula that looks at a cell and determines what range the cell is between and then fills another cell with a specific value depending on the target cell's value. This is the formula I've created:
=IF(AND(C4>0,C4<5,1,IF(AND(C4>=5,C4<8,2,IF(C4>=8,3)))))
Where C4 is the number of hours an employee worked in one day. I'm trying to determine if they were eligible for 1, 2 or 3 10 minute breaks and assign that value to C6.
What I'm getting is this message:
Error
Wrong number of arguments to IF. Expected between 2 and 3 arguments,
but got 1 arguments.
How do I fix this?

IF() function should have two parameters and optionally a third one.
IF(logical_expression, value_if_true, value_if_false)

The IF statement works as follows:
IF(logic_test, value_if true, value_if_false)
Your first IF statement has only the logic_test part (the output of AND). so you have to provide the other parameters.

Related

How to give a cell containing with 'ISREF' a default value in Google Sheets

I am trying to use a formula that uses INDEX function. In order to generalize for all the lines that sometimes may contain information from another sheet and sometimes they may not.
That's why I get an ISREF error within the cells because the corresponding cells in the other sheet can't be referenced.
I want to display a default value instead of the ISREF error message. I tried using ISREF function itself within an IF condition but it doesn't work on the same cell. It only references another cell because it is a cell checking function and it doesn't check the output of a formula.
I tried also ISERROR function but it didn't work also. Here's a snippet of the formula that I am putting within my cell:'
INDEX(Plagesuivi; $Q203; 9)
Plagesuivi is a named range
$Q203 contains the row number (that I fetch dynamically and correctly)
9 is the column number
P.S. The indexing is working fine with cells that do appear is the named range: Plagesuivi
I would go with iferror() like this:
=iferror(INDEX(Plagesuivi;$Q203;9);0)
Or replace the 0 with ""
After trial and error the best way to avoid all sorts of errors is:
= IF($Q203=""; 0; IFERROR(INDEX(Plagesuivi; $Q203; 9); 0))
IFERROR checks for all sorts of unpredictable errrors it is a safe-guard against unpredicted cases where it takes 0 by default.
IF in the second case checks whether the referencing content of Q203 is empty or not, in case it is empty the cell takes 0 by default else it gets the output of the false case formula.

How to get rid of the array size error in this scenario while using Countifs()

I have two columns and am trying to count the nonblank cells in column B based on a specific corresponding value in column A. So I am using COUNTIFS($A$3:$A,"GA",len(trim($B7:$B)),">0") to calculate that.
First criteria range is Column A and the criteria is if cell value equals "GA".
I want the second criteria range to be Column B and the criteria to be len(trim(cell)) > 0 but obviously I am not specifying it correctly and getting the following error, instead of the expected result of 7.
Please help in how I should achieve this.
Typo? Should be...
=COUNTIFS($A$3:$A,"GA",len(trim($B3:$B)),">0")
(You had $B7:$B.)
You can shorten this anyway:
=COUNTIFS(A3:A,"GA",B3:B,"<>")

Why INDIRECT function returns a 1?

I'm trying to return a count of names from another sheet (it's a list of names in Column A and I want to pull the # of individual names into a cell in another sheet). I have many sheets with varying lists of names. I'm using the COUNTA(INDIRECT function, but I keep getting "1" as the result.
=COUNTA(INDIRECT("'"&A2&"'!A:A))")
Can anyone help?
You're nearly there, just have to move the last quote inside the brackets and remove the extra bracket.
=COUNTA(INDIRECT("'"&A2&"'!A:A"))
to account for errors such as "nothing to count" you will need:
=COUNTA(IFERROR(INDIRECT("'"&A2&"'!A:A")))
and btw that was the reason why you were getting 1 from your formula attempt because COUNTA counted the error.

How to compare 2 different columns in Google Sheet

I have two columns I'd like to compare data in. The first column has about 50 rows, whereas the second column has 200 rows.
I would like to be able to tell if any cell in the first column matches up with a value in the second column.
I first tried this with the QUERY() function
=QUERY(A12:B, "Select A where A = B")
but this didn't seem to work, I got a circular dependency error.
I then tried the array function.
=ARRAYFORMULA(if(A12:A=B12:B,"REMOVE_ME", "DON'T REMOVE ME"))
but this was outputting incorrect values. Is there an easier way to do this or am I missing something?
Here is sample data: https://docs.google.com/spreadsheets/d/1IVUksDc79uJPfe6_Yfkp-EBelzh-U3q1EIiYlguQoRw/edit?usp=sharing
The value 6 is given MATCH because there is a value 6 somewhere in Column B.
Use this formula in C2:
=IFERROR(IF(VLOOKUP(A2,$B$2:$B$22,1,0)>0,"MATCH","NO MATCH"),"NO MATCH")

How to use INDEX() inside ARRAYFORMULA()?

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)

Resources