Last active
November 7, 2023 15:09
-
-
Save adgedenkers/9896c3393ddc5cf7d1b6cdc3cd753dc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IF Statements in Excel | |
=if( [logical-condition], [result-if-true], [result-if-false] ) | |
Example: | |
=if( [STATION]="101", "New-York", "Not-New-York" ) | |
// If [STATION] equals "101", then set the cell value to "New-York", otherwise set it to "Not-New-York". | |
Now, more than one [STATION] may be associated with "New-York", so we must add an OR statement into the mix. | |
=if( OR( [STATION]="101", [STATION]="103") , "New-York", "Non-New-York" ) | |
// If [STATION] equals "101" or "103", then set the cell value to "New-York". | |
To test more than 2 possible values in your condition (like, if [STATION] equals "101", "103", "104", "116", etc., you must nest multiple IF statements together, since the OR statement can only test two values. | |
Nesting 3 IF statements will look somewhat like this: | |
=if( [logical-condition], [result-if-true], if( [logical-condition], [result-if-true], if( [logical-condition], [result-if-true], [result-if-all-above-are-false] ) ) ) | |
So in the example below, we're looking to see if the field [STATION] is equal to either "101, 103, 104, 116, 200, or 215". Since the OR statement will only accept two arguments (either [STATION] = "101" OR [STATION] = "103"). So if we want to check six possible values, you have to do a total of 3 IF statements (1 statement per 2 conditions to test). | |
// ------------------------------------------------------------------------- | |
=if(or([STATION]="101",[STATION]="103"), "New-York", // Is STATION either 101 or 103? If YES, set value to "New-York", otherwise keep going ... | |
if(or([STATION]="104",[STATION]="116"), "New-York", // IS STATION either 104 or 116? If YES, set value to "New-York", otherwise keep going ... | |
if(or([STATION]="200", [STATION]="215"), "New-York", "Not-New-York") // IS STATION either 200 or 215? If YES, set value to "New-York", otherwise (since we've tested everything else) set value to "Not-New-York" | |
) | |
) | |
// ------------------------------------------------------------------------- | |
Complete statement on 1 line: | |
=if(or([STATION]="101",[STATION]="103"), "New-York", if(or([STATION]="104",[STATION]="116"), "New-York", if(or([STATION]="200", [STATION]="215"), "New-York", "Not-New-York"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment