The error was actually just a simple syntax issue - the placement of your parentheses - here is the correct:
=IF(H4=1, "CORRECT", IF(H4=2, "CORRECT", IF(H4=3, "CORRECT")))
I also fixed it on your spreadsheet.
Every if statement must have 3 parts essentially, so if(this, then this, else this) so when nesting, the else this part of the formula is the next condition..
=IF(h4=1, "CORRECT", IF(h4=2, "CORRECT", IF(h4=3, "CORRECT", IF(h4=4, "CORRECT"))))
Answer from Aurielle Perlmann on Stack OverflowSOLVED | Hi All
Could anyone please give me some direction on possibly not using a bunch of messy nested IF Statements to build my Fee Calculator. Essentially I plug in a Construction Value and want it to check against it the Value of Works Scale, match the appropriate row and then use the corresponding data for the formulas.
Test Link: https://docs.google.com/spreadsheets/d/1xHVtbkde8GEmBYCEnqQ3ArNIhzomdTsVsNpwwTgqOZU/edit#gid=953131243
What is the alternative to nesting IF statements? - Google Docs Editors Community
google sheets - Alternate to Nested IF statements - Web Applications Stack Exchange
How to include multiple IF statements in one cell in Google Sheets - Web Applications Stack Exchange
Script alternative to nested IF statements Google Sheets, ignore text cells - Stack Overflow
Does Coefficient work with both Google Sheets and Excel?
What is Coefficient's AI Sheets Assistant?
How does Coefficient's automated refresh work?
The error was actually just a simple syntax issue - the placement of your parentheses - here is the correct:
=IF(H4=1, "CORRECT", IF(H4=2, "CORRECT", IF(H4=3, "CORRECT")))
I also fixed it on your spreadsheet.
Every if statement must have 3 parts essentially, so if(this, then this, else this) so when nesting, the else this part of the formula is the next condition..
=IF(h4=1, "CORRECT", IF(h4=2, "CORRECT", IF(h4=3, "CORRECT", IF(h4=4, "CORRECT"))))
Short answer
Instead of nesting multiple IFs, try to use a formula that doesn't require that. Considering the example provided, one alternative is the following:
=IF(AND(h1>=1,h4<=4),"CORRECT")
Explanation
If it's possible, avoid function nesting as it could make a formula harder to read and debug.
Use lookup instead of if:
=lookup(B7,
{"#000000","#00ff00","#ff0000","#ff9900"},
{"Not applicable", "Read","Unread","In Progress"}
)
Note the second parameter must be a sorted list.
Short answer
The problem in the examples provided are the parenthesis. Apply them properly.
Explanation
IF() function should have two parameters and optionally a third one.
IF(logical_expression, value_if_true, value_if_false)
The specific problem with
- the first example provided is that the outer
IF()has too many parameters. - the second example is that the
logical_expressionof the outerIF()do not returnTRUEorFALSE
In Google Sheets the functions parameters are separated by commas (or semicolons if your spreadsheet uses comma as decimal separator). When parenthesis are used to enclose several operations and functions inside a function they are considered as a parameter of the function that contains them.
A common practice is to put the inner IF() as the value_if_false, but it could be done in many ways. Adding IF() inside another other as value_if_true and value_if_false is called IF() logical test nesting or just IF() nesting.
Below is an example of a formula that have having three IF(), two of them used to determine the value_if_false of the parent IF(). A multi-line and vertical align of parenthesis style is applied for readability
=IF(logical_expression, value_if_true,
IF(logical_expression, value_if_true,
IF(logical_expression, value_if_true, value_if_false
)
)
)
The above style could be used in Google Sheets formula writing. I found it useful for formula debugging.
Reference
- IF - Google Docs editors Help
Ryan, I feel obliged to say that this isn't an ideal data setup. That said, if you're committed to keeping it, you can accomplish your goal with a version of the following (which I have placed in your second vertical block reading "January 2018":
=INDEX(14:14,MATCH(1,(ISNUMBER(15:15)*(15:15>0)),0)-2)&" "&INDEX(14:14,MATCH(1,(ISNUMBER(15:15)*(15:15>0)),0))
To use it elsewhere, just change the row range 14:14 to match your upper text row with the months and years, and change 15:15 to match the row where your currency amounts are.
HOW IT WORKS
First, spot the &" "& in the middle. Everything before this results in the month name. Everything after it results in the year. The ampersand(&) means "stick these together." So we will get monthname+onespace+year in the end.
The portion of the formula that retrieves the month and the portion that retrieves the year work similarly:
INDEX(14:14,_____)
In English, "Look across row 14."
MATCH(1,_____,0)
We are going to create a virtual row of true or false values that match up with every cell in row 14. In programming, a 1 means TRUE (or "Yes" or "I found it") and a 0 means FALSE (or "No" or "I didn't find it").
The zero at the end of the match means we want an exact match. It answers the question "Will you accept something close?" to which our answer is FALSE / NO (or, as I explained, 0 for that part).
ISNUMBER(15:15)*(15:15>0)
We are trying to test two conditions here in order to find our MATCH:
First condition: ISNUMBER(15:15) This tests every cell in row 15 to see if it is a number. Those cells that contain a number will earn a 1 (for TRUE/YES). Those cells that do not contain a number will get a 0 (FALSE/NO).
Second condition: (15:15>0) This is a second test on every cell in row 15 to see if it is contains a value greater than zero. If it does, that cell gets a 1; if not, it gets a 0.
The asterisk multiplies our first answer by our second answer. So for instance, if the first cell in row 15 held text, it would get a score of 0 (FALSE) for "Is it a number?" and 0 (FALSE) for "Is it greater than zero?" The cumulative score, then for that cell would be 0 * 0 or ... just 0.
As the formula looks across row 15, if it finds a negative number, the test returns 1 (TRUE) for "Is it a number?" and 0 (FALSE) for "Is it greater than zero?" The cumulative score for this cell will still be 0, because 1 * 0 = 0.
So the only cells that will get a 1 will be those that both contain a number and are greater than zero (which is what you're looking for).
In the end, let's say that row 15 had 25 cells in it. The virtual "array" (i.e., list) that ISNUMBER(15:15)*(15:15>0) creates will look something like this:
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0}
Remember, the MATCH function will be looking for the first instance of 1:
MATCH(1,(ISNUMBER(15:15)*(15:15>0)),0)
When it finds it, we know which column the first match is in.
Back to INDEX:
INDEX(14:14,MATCH(1,(ISNUMBER(15:15)*(15:15>0)),0))
INDEX will return the value in row 14 that matches the spot where MATCH found TRUE*TRUE (or 1). So we would now wind up with the YEAR from row 14 that's above the first numeric value greater than 0 in row 15.
But we want that second (which is why you'll see this exact formula portion after the &" "&).
In order to get the month, we just back up two cells from the year. So the first part of the formula, before &" "&, adds a -2:
INDEX(14:14,MATCH(1,(ISNUMBER(15:15)*(15:15>0)),0)-2)
In other words, look across row 14 until you find the TRUE/TRUE match in row 15, then back up 2 from where you find it.
In the end, we get:
=INDEX(14:14,MATCH(1,(ISNUMBER(15:15)*(15:15>0)),0)-2) (month name)
&" "& (and a single space and)
INDEX(14:14,MATCH(1,(ISNUMBER(15:15)*(15:15>0)),0)) (year)
My answer is a variation on @erik-tyler's answer
Using FILTER
=JOIN(" ", INDEX(FILTER({C2:T2; E2:V2}, 1/(1/E3:V3)>0),,1))
Your approach to organizing data works against you. You could store dates as numbers instead of text but display them however you want.
For example, if instead of the text string "2019" you entered the date January 1, 2019 (according to your locale) or the numeric equivalent 43466 you could apply the custom format "yyyy" to that cell.
Now your formula could be simplified to:
=INDEX(FILTER(E2:V2, 1/(1/E3:V3)>0),,1))
or using @erik-tyler's approach
=INDEX(14:14,MATCH(1,(ISNUMBER(15:15)*(15:15>0)),0))
=IF(OR (AND(C1="NYC",OR(B1="Friday",B1="Monday")), ((D1+35)*E1), (D1*E1) ), IF( AND(C1="Chicago",OR(B1="Friday",B1="Monday")), ((D1+30)*E1), (D1*E1) ) )
D1=Base rate
E1=Number of hours worked
This calculates the daily wage of employees based on the city they worked in. If they worked in NYC or Chicago, there is a higher rate for Mondays and Fridays worked ($35 higher for NYC and $30 higher for Chicago).
The formula works for Chicago for all days but for NYC, it's not reflecting the correct amount for Mondays and Fridays, but returns the daily total at the base rate.
Driving me crazy! Any help is appreciated!