Using IF function, getting "too many - if-statement

HELP! I'm getting a "too many arguments for this function" error.
=IF(B13>149,000,"T1",IF(B13>180,000,"T2",IF(B13>210,000,"T3",IF(B13>240,000,"T4",IF(B13>270,000,"T5",IF(B13>300,000,"T6"))))))

Remove the commas from the numbers; Excel thinks "comma" means "new argument." Like this...
=IF(B13>149000,"T1",IF(B13>180000,"T2",IF(B13>210000,"T3",IF(B13>240000,"T4",IF(B13>270000,"T5",IF(B13>300000,"T6"))))))
...but your code will still not do what you want it to do because assuming B13 is greater than 149000, we'll never get past evaluating your first IF and setting to T1, because it looks like the function parser stops after it finds a true condition (like B13 being greater than 149000; whether or not other IFs in your function would also evaluate to true doesn't matter to Excel - it already found a true condition). The solution is to reverse the order, like this:
=IF(B13>300000,"T6",IF(B13>270000,"T5",IF(B13>240000,"T4",IF(B13>210000,"T3",IF(B13>180000,"T2",IF(B13>149000,"T1"))))))

Related

Google Sheets: How to create a nested IF statement with MATCH function?

I have been looking for a solution to this for quite a few hours, but unfortunately I appear to be stuck. I am trying to automatically input data based on another sheet with three possible options. DEADLINE, PMC or FMC, but it keeps crashing with if it can't find the first result. It will say #N/A, and tells me it can't find the first value. Why doesn't it check for the other values?
=IFS((MATCH(J8,Faults!F3:F9,0)),"DEADLINE",(MATCH(J6,Faults!F3:F9,0)),"PMC",(MATCH(J4,Faults!F3:F9,0)),"FMC")
Thanks in advance
MATCH does not return TRUE or FALSE. It either returns a number (the position within the range) or a #N/A error.
IFS will throw an error and stop processing just as a nested IF will. Wrap all the match functions in ISNUMBER to bypass thrown #N/A errors on no match.
=IFS(isnumber(MATCH(J8, Faults!F3:F9, 0)),"DEADLINE", isnumber(MATCH(J6, Faults!F3:F9, 0)), "PMC", isnumber(MATCH(J4, Faults!F3:F9, 0)), "FMC", true, "other")
I've added a default of Other if none of the three matches are found.

Is there a way to exact match "truthy" and "falsey" values in ColdFusion

I recently had the need to match against two strings in ColdFusion and ran into this scenario during my loop:
<cfif "0" IS NOT "NO">
Generally during the loop it looks something like this:
<cfif "AM" IS NOT "BA">
Now both of these values were variables (I wasn't just typing it out for fun) and I was using "0" as a default value for the first variable to match against (since the second variables would never be 0) but both of these values changed in the loop I was running. I easily fixed this by setting my default value to -- instead of 0 but I tried researching and found nothing indicating there was a way to get around the falsey nature of strings when evaluating them.
Is there no Operator or trick to match on the strings themselves and ignore their truthyness or falseyness in ColdFusion?
The compare function will help you. This:
writedump(compare("0", "NO"));
returns -1.
This page will tell you what that means.

If-Else conditions with APL?

So, I'm wondering/asking; Is it possible to do an If-Statement in APL? If so how?
Here's my code
'Please enter a number to count to: '
number ←⎕
⍳number
How do I get an if-statement to where if the user inputs a number over 100 it will print out "too high" and end; or if it's 100 or under then it will just continue?
Thanks!
In Dyalog APL you have this neat little thing called guards.
They can be used in dfns and evaluate code when a certain condition matches.
func ← {⍵>100 : 'too high' ⋄ 1 : 'number is ok'}
If your APL supports control structures then this should work:
∇ generateAll number
:If number>100
⎕←'Too high'
:else
⎕←⍳ number
:endif
∇
If it does NOT support control structures (like APL2) you will need to branch:
∇ generateAll number
→(number>100)/error
⎕←⍳ number
→0
error:
⎕←'Too high'
∇
You can also use tricks like execute but this is less readable.
A "classical" way of doing error handling* in APL2 is with the ⎕ES or ⎕EA.
Your code would look something like this:
⎕ES(NUMBER>100)/'Too high'
⍳NUMBER
What happens here is that IF the parentheses evaluate to true, THEN the ⎕ES will halt the execution and echo the quoted string.
If you don't want your THEN to terminate, have a look at ⎕EA in some APL documentation.
Please note that I'm on APL2 in a GreenOnBlack environment, so there are likely more neat ways of doing this in a more modern dialect like Dyalog.
*I know you're asking about conditionals and not error handling, but since you're example terminates execution, it might as well be error handling.
There is a crucial difference between this and what MBaas suggests: His solution will gracefully exit the current function which might return a value. Using ⎕ES or ⎕EA with terminate all execution.
Depends on the dialect you're using. Some APL-Implementations support control-strucures, so you could write something like
:If number>100
⎕←'Too high'
→0
:endif
⍳number
In "tradtional APL" you would probably do something like
⍎(number>100)/'⎕←''Too high'' ⋄ →0'
⍳number

Nesting AND NOT ISBLANK with MULTIPLE IFs

I can't find an example close enough to this one on StackOverflow so here goes:
I want to return a message "Type?" if cell X is blank and cell Y has any text. But I'm trying to nestle it into an existing set of IFs.
Existing :
=IF($G241="Evo";M241*L241;IF($G241="Free";M241*L241;IF($G241="GN";M241*L241))))
Nestling this into the above:
=IF(AND(NOT(ISBLANK($J234));ISBLANK(G234));"Type?";"OK")
I tried this but it returns FALSE, maybe due to the AND I'm using, which I need since I'm creating a return based on two cells two cells.
=IF($G240="Evo";M240*L240;IF(AND(NOT(ISBLANK($J240));ISBLANK(G240);"Type?";"OK");IF($G240="Free";M240*L240;IF($G240="GN";M240*L240))))
getting Error:
AND expects boolean values. But 'Type?' is a text and cannot be coerced to a boolean.
IF(and(isblank(cell x),iferror(isstring(cell y),false)),"Type?","OK")
That should do it for you I think. you will need to replace cell x and cell y with the appropriate references. The iferror statement is there to catch what happens when evaluating a blank cell y.
The problem with this formula
=IF($G240="Evo";M240*L240;IF(AND(NOT(ISBLANK($J240));ISBLANK(G240);"Type?";"OK");IF($G240="Free";M240*L240;IF($G240="GN";M240*L240))))
is you are trying to check G240 for different values when it cant. Lets simplify your formula. We will replace your empty cell check with FORMULA 1
=If($G240="EVO", Do True Condition, Do Formula 1, IF(G$240=Free, Do Free True Condition, Do Free False Condition)
The problem is since you already did something (Formula 1) when G240 = "EVO", you cant start another check on what G240 after the fact with the way you have embedded your formula. a batter way of thinking of it is how to do a second check when G240="EVO" is false. Remember the general format of an if statement is:
IF(CONDITION,True Result, False Result)
There are only 3 things that go into an if statement. you tried putting in 3.
Try rearranging to this:
=If($G240="EVO", Do True Condition, IF(SOME CHECK to determine DO FOMULA 1 or CHECK for G240 = FREE, Do Formula 1, IF(G$240=Free, Do Free True Condition, Do Free False Condition)))
Basically break down what you want to check for in G240 and do it in sequence with your IF statement. Right now with what you have written, I cant tell how you want to determine if you want to run your formula 1 or if you want to check if G240="free" since you have two different outcomes if G240="Free"/
OK I think i found the issue. The IF(AND(NOT(ISBLANK works on it's own since there are no other IFs in the formula. I do want to test two different cells for text(letters) in order to show a warning if one cell was blank while the other not. But as soon as you insert the (AND into a string of multiple IFs it doesn't work.
Simply removing the (AND was all I needed to do. Another way to achieve a test for more than one blank cell was to simply add multiple IF(ISBLANKs.
EG: =IF(ISBLANK(A1)+IF(ISBLANK(A2)>2;condition true;condition false)
ForwardEd thanks very much for your help!
Regards

What is this ColdFusion evaluation actually doing?

I'm reviewing some code inside of a cfmodule it got me scratching my head.
The cfmodule is being called like:
<cfmodule template="/cfmods/mod1.cfm" mode="breadcrumbs">
and the code inside has a series of cfelse statements but this one is the one that gave me pause.
<cfelseif isdefined("attributes.mode")
AND NOT comparenocase("breadcrumbs", attributes.mode)>
Can someone translate this into spoken words? I know CompareNoCase will return a negative number, 0, or a positive number as a result. So what does adding the the word not do, check for the opposite of what was returned from CompareNoCase?
AND (CONDITION) checks if the condition is TRUE.
AND NOT (CONDITION) checks if the condition is FALSE.
So that statement is saying:
If Attributes.Mode exists as a variable and attributes.mode IS EQUAL to Breadcrumbs regardless of case, THEN...