Multiple IF statements in an Excel spreadsheet - excel

I've researched this quite a bit but to no avail, I've tried to do a choose with:
=CHOOSE(MATCH(R5,{"PASS","MERIT","DISTINCTION"},FALSE),"70","80","90")
Alternatively I've done:
=IF(R5="PASS","70"), IF(R5="MERIT","80"), IF(R5="DISTINCTION","90")
The plan is to see what the input would be for the cell R5, if it is pass then the cell that is selected which is U5 would show the appropriate points.
Pass is 70 points, Merit is 80 and a Distinction would be 90 so you can see my reasoning behind the choices in my code. Not entirely sure how to go about it. Also tried using ORs in the IF statement but I might not have coded it in completely correctly.

The Excel IF statement is defined as:
=IF(condition,value_if_true,value_if_false)
You can substitute the values with additional statements, so it becomes:
=IF(R5="PASS","70",IF(R5="MERIT","80",IF(R5="DISTINCTION","90")))
This is equivalent to the following pseudo-code:
if(R5 equals "PASS"){
"70"
} elseif (R5 equals "MERIT") {
"80"
} elseif (R5 equals "DISTINCTION") {
"90"
}

Related

Combining 6 IF formulas

I've written 6 different IF formulas, each will identify a freight carrier based on the tracking number found in cell BM71.
For the life of me I cannot figure out how to combine these, any help would be appreciated.
=IF(AND(LEN(BM71)=18,LEFT(BM71,2)="1Z"), "UPS", "")
=IF(AND(LEN(BM71)=12,ISNUMBER(BM71)),"FedEx","")
=IF(AND(LEN(BM71)=10,ISNUMBER(BM71)),"DHL","")
=IF(AND(LEN(BM71)=11,LEFT(BM71,2)="06"), "Old Dominion", "")
=IF(AND(LEN(BM71)=9,LEFT(BM71,2)="00"), "Arcbest", "")
=IF(AND(LEN(BM71)=10,LEFT(BM71,2)="00"), "Averitt", "")
With ifS function it gets more clean:
=IFs(AND(LEN(BM71)=18,LEFT(BM71,2)="1Z"), "UPS",
AND(LEN(BM71)=12,ISNUMBER(BM71)),"FedEx",
AND(LEN(BM71)=10,ISNUMBER(BM71)),"DHL",
AND(LEN(BM71)=11,LEFT(BM71,2)="06"), "Old Dominion",
AND(LEN(BM71)=9,LEFT(BM71,2)="00"), "Arcbest",
AND(LEN(BM71)=10,LEFT(BM71,2)="00"), "Averitt",
True,"")
You just add a new IF in the False part. Like this:
=IF(AND(LEN(BM71)=18,LEFT(BM71,2)="1Z"), "UPS",
IF(AND(LEN(BM71)=12,ISNUMBER(BM71)),"FedEx",
IF(AND(LEN(BM71)=10,ISNUMBER(BM71)),"DHL",
IF(AND(LEN(BM71)=11,LEFT(BM71,2)="06"), "Old Dominion",
IF(AND(LEN(BM71)=9,LEFT(BM71,2)="00"), "Arcbest",
IF(AND(LEN(BM71)=10,LEFT(BM71,2)="00"), "Averitt", ""))))))
No love for LET?
Something like:
=LET(x,BM71,l,LEN(x),b,ISNUMBER(x),s,LEFT(x,2),IFS(
(l=18)*(s="1Z"),"UPS",
(l=12)*b,"FedEx",
(l=10)*b,"DHL",
(l=11)*(s="06"),"Old Dominion",
(l=9)*(s="00"),"Arcbest",
(l=10)*(s="00"),"Averitt"))
If nothing else it cuts down the formula length, and the function only takes one input cell reference (rather than 12 ...).
EDIT: Though if it were me (as other comments have mentioned) I would use this:
=LET(x,BM71,l,LEN(x),b,ISNUMBER(x),s,LEFT(x,2),c,IFS(
(l=18)*(s="1Z"),1,
(l=12)*b,2,
(l=10)*b,3,
(l=11)*(s="06"),4,
(l=9)*(s="00"),5,
(l=10)*(s="00"),6,
TRUE,7),INDEX(Carriers,c) )
With the range named Carriers holding the list of carriers, with a blank in the last row. Makes it easier to change a carrier name and you keep the list in one place which can be re-used by other formulas. (But then I am a devotee of the Third Normal Form ...)
You can add next one instead of "" of previous formula
=IF(AND(LEN(BM71)=18,LEFT(BM71,2)="1Z"), "UPS", IF(AND(LEN(BM71)=12,ISNUMBER(BM71)),"FedEx",IF(AND(LEN(BM71)=10,ISNUMBER(BM71)),"DHL",IF(AND(LEN(BM71)=11,LEFT(BM71,2)="06"), "Old Dominion", IF(AND(LEN(BM71)=9,LEFT(BM71,2)="00"), "Arcbest", IF(AND(LEN(BM71)=10,LEFT(BM71,2)="00"), "Averitt", ""))))))
However you approach to define something based on length and some chars is not stable
I hope I could help you

If(AND) combination produces "You've entered too many arguments for this function" error

hello everyone I'm here and needs help with excel
message from excel is
(you've entered too many arguments for this function)
and that my function.
=IF(AND(H2="A","B"),"group 1",IF(AND(N2H2="C","D"),"group 2",""))
please any one can help ?
The first condition to test within the IF statement "AND(H2="A","B")" will always return false - as this tests "Is H2 = "A" ? AND "Is '"B"'?
H2 cannot equal "A" and "B" simultaneously, and besides, even if you wanted to test that you'd have to use "AND(H2="A", H2="B").
Imagine someone asking you the Q "Is H2 = "A"?"
You could answer this if you knew what was in cell H2 (like Excel does) - and you could answer 'True' (yes) or 'False' (no).
But if you were asked is "B" as well? you would probably be quite puzzled - perhaps you would reply "Is "B" what as well"?
Excel would also be puzzled and in such circumstances the default response is 'False' (until proven otherwise!)
The 2nd AND statement is the wrong syntax - see here for some examples of how to use the AND statement.
This is probably why you are seeing the error you see - again:
If someone asked you "Is N2H2="C" and is "B" as well?
You wouldn't know which cell I was referring to (N2H2 does not exist in Excel)
Further, you wouldn't know what to say to "Is "B"?" (Is it a consonent? Is it capital? Is it the 2nd letter of the alphabet? Is it what?
Using this equation Excel will not return an error "too many arguments", it will return "invalid name error" (because there is no such thing as "N2H2" as far as Excel is concerned")
You need to use the following generic syntax for AND statements of this type:
AND(cell 1=some value1, cell 2= some value2) - not AND(cell1cell2=some value1, some value2)
i.e. this would be correct syntax:
=IF(AND(H2="A",N2="B"),"group 1",IF(AND(H2="D",N2="C"),"group 2",""))
(but it assumes you are trying to test cell N2 = B in the first AND statement because it's impossible for cell H2 to equal both A and B at the same time as I've said above)
As someone has pointed out in the comments - if you're testing whether H2 can be "A" OR "B" then simply use the OR statement - i.e. something like this:
=IF(OR(H2="A",H2="B"),"group 1",IF(AND(H2="D",N2="C"),"group 2",""))
https://support.microsoft.com/en-us/office/and-function-5f19b2e8-e1df-4408-897a-ce285a19e9d9

Combining CONCAT, DATEDIF, and nested IF -getting #VALUE! error

Trying to fill an investment field with Short/Long Term & Capital Gain/Loss. Ending values should be one of the following - STCG, STCL, LTCG, LTCL. (I tried to cut/paste an excel image but it's icky, sorry)
Mini Spreadsheet - Date Acquired (H62), G/L per share (J62), Position (result)
For some investments, the date acquired is Var (for various purchases) or blank (for cash). If it is "Var", the function should return "LT" and skip the DATEDIF function. If the date is blank, the function should be skipped entirely and return blank as there is neither gain nor loss.
=IF($H62="","",CONCAT(IF(OR($H62="Var", DATEDIF($H62,TODAY(),"d")<365),"ST","LT"),IF($J62<0,"CL","CG")))
My original function worked well, except when the Date Acquired field (H62) had "Var", I got a #VALUE! error. I tried to do this with nested IFs and with IFS function, but couldn't get it to work (Problem with this formula error): =IF(H61="","",CONCAT(IF($H61="Var", "LT",IF(DATEDIF($H61,TODAY(),"d")<365),"ST","LT")),IF(J61<0,"CL","CG")))
The logic should be: If date="" then "" else concat LT/ST test and CL/CG test
LT/ST test: If date="Var" then "LT" else if date days before today < 365,"ST" else "LT"
CL/CG test: If gain per share <0 "CL" else "CG" (working)
Please help! I could add a hidden column (I'd rather not) or do the whole thing with nested IFs or IFS but I'd have to repeat arguments and that's sloppy & asking for trouble.

OR Formula in Word document not returning a value

I am working on a document where I need to be able to test multiple options in an if statement to see if one of them are true to decide if a paragraph displays on the document. I have been trying to figure out why my OR formula is not returning a value for me to test and I am not sure why it is not showing anything when it is updating.
I have inserted a field and added a formula within that field that I am hoping will work with my If statement to show the proper paragraph contens.
When I use an Or statement, even one as simple as { OR(1=1) } and update and toggle the field I get no result. From what I have read I should get a 1 or a 0, but I don't seem to get either of these results. The line just ends up blank. When I test it with my If formula it always shows the false result, even when the Or contains a true result.
The formula I am currently working with is:
{ IF{ OR("$event.eventType.name}" = "Birthday", "$event.eventType.name}" =
"Conference" } "Yes" "No" }
If I update and toggle the Or field it shows blank, no result either true or false, and makes the If formula show as false event on results where it should show true. As I mentioned above I even tried setting it to 1=1 and still could not get it to show as true. Not sure if there is something I am missing in working with the formula.
Any suggestions would be appreciated.
It's not clear from your post what $event.eventType.name is. Presumably it's a field generated by an Addin. In that case, you should be able to use something like:
{IF{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0}# 0}> 0 "Yes" "No"}
or:
{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0} \# "'Yes',,'No'"}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. If your fields are a kind of mergefield, you'll need to insert 'MERGEFIELD ' at the start of each one, thus:
{MERGEFIELD $event.eventType.name}

Nested IF statement returning false

I have a nested if statement is returning "False" rather than the expected outcome.
Scenario
Table "High VoltageCables" has data in it that default to numeric but may contain characters: kVa
Table "Master" checks "High VoltageCables" data as blank or not blank, and returns "Failed Check 1","Passed Check 1". This works fine.
Table "Meta" then checks the results of "Master" and then tests "High VoltageCables" data for length between 1 and 6, regardless of whether record is numeric or string.
Formula
=IF(MASTER!H2="Passed Check 1",IF(LEN('High VoltageCables'!O2)>=1,IF(LEN('High VoltageCables'!O2<6),"Passed Check 2","Failed Check 2")))
This is partially succesful, as it returns "Passed Check 2" for the following sample data in the source table "High VoltageCables".
1 numeric, or
1kVa str, or
50000 numeric
However if a field in "High VoltageCables"is blank, the formula returns "FALSE" rather than "Failed Check 1"
I inherited this task, (and would have preferred to do the whole thing in Access using relatively simple queries) - and unfortunately I am new to nested If statements, so I am probably missing something basic...
NB the data in High VoltageCables must default to numeric for a further check to work.
The first and second IF's seem to be missing the else part. They should be added at the end between the ))) like ), else ), else )
Every IF statement consists of IF( condition, truepart, falsepart) if you have two nested ifs it will be something like IF( condition, IF( condition2, truepart2, falsepart2), falsepart)
Hope that makes it a little clearer
You do have an unaccounted for FALSE in the middle IF. Try bring the latter two conditions together.
=IF(Master!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"))
It's still a bit unclear on what to show or not show if Master!H2 does not equal "Passed Check 1".
I failed to construct the formula with a concluding "else" - "Failed Check 1"
Using jeeped's and Tom's suggestion and adding the final "else" part I have solved the problem:
=IF(MASTER!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"),"Failed Check 1")

Resources