Use IF and IF AND in the same formula - excel-formula

I believe my sytanx is right but I cannot use IF and AND IF statements in the same formula. Do you know what the issue might be?
=IF(K47>170,"BAD",IF(K47<100,"GOOD"),IF(AND(J47=0,I47>160,"BAD")

In excel If is (boolean statement, true result, false result)
And just returns true or false. You can't have a string value.
so And should be throwing an error because "BAD" can't be evaluated as true or false
and the last if should throw an error because there are enough arguments (it needs three).
In addition, you don't have enough to bound the formula.
So you should have something like
=if(K47>170, "Bad", if(k47< 100, "Good", if(AND(J47=0,I47>160), "BAD", "SOMETHING")))

Break it down into smaller blocks to isolate the problem. Not tested because I don't have excel but writing the formula as follows
=IF(
K47>170,
"BAD",
IF(
K47<100,
"GOOD")
^^ looks like you're missing something here because the else part of the innermost if here isn't specified and the statement should be closed with a ) here, meaning excel can't figure out what to do with the rest (below).
,IF(AND(J47=0,I47>160,"BAD")
This part also has a pretty strange condition. It seems like you want to say " if j47 equals 0 and I47 is greater than 160 ".
In pseudo code, if you want
if k47 > 170
bad
else
if k47 < 100
good
else
if j47 = 0 and I47 > 160
bad
else
good
end
end
Then you can write it with excel with something like
=IF(
K47 > 170,
"BAD",
IF(
K47 < 100,
"GOOD",
IF(
AND(
J47 = 0,
I47 > 160
),
"BAD",
"GOOD"
)
)
)
Give it a try and look at the excel formula guide as you go, solving one piece at a time.

Related

Google Sheet double TRUE giving a FALSE

I got a weird case of 2 TRUE giving a FALSE.
I got this formula (I reduced it to only have the case that interest me for debugging purpose.:
=ARRAYFORMULA(
IF(ROW(JS7:JS)=7,JR7+1,
SWITCH($F7:$F,
"M",1,
"D",2,
"W",3,
"B",IF(AND(JS$7 >= 'A 2021'!$E7:$E,mod(('A 2021'!$E7:$E-JS$7),14)=0),$D7:$D,4),
"A",5,
"O",6,
0)
)
)
Basically this formula check if the row is the 7th, if yes, add 1 to the previous date to get the next day (this part is fine), else it goes into the Switch to return a value (0 to 6) based on other columns (in my case it is the "B" and should return 4).
This part in the formula return a FALSE:
AND(JS$7 >= 'A 2021'!$E7:$E,mod(('A 2021'!$E7:$E-JS$7),14)=0
yet JS$7 >= 'A 2021'!$E7:$E (checking if we are past the current date) is TRUE and mod(('A 2021'!$E7:$E-JS$7),14)=0 (using modulo to check if we are every 2 weeks) is also TRUE
I tried to replace the returned value of 4 by JS$7 >= 'A 2021'!$E7:$E to see its value and it was TRUE, same thing for the mod(). But when I tried with the AND(), it returned FALSE, yet, that AND() is made of previous parts that both returned TRUE.
Am I doing an obvious mistake here or something is fishy?
AND is not supported under ARRAYFORMULA. try:
=ARRAYFORMULA(
IF(ROW(JS7:JS)=7,JR7+1,
SWITCH($F7:$F,
"M",1,
"D",2,
"W",3,
"B",IF((JS$7 >= 'A 2021'!$E7:$E)*(MOD(('A 2021'!$E7:$E-JS$7),14)=0),$D7:$D,4),
"A",5,
"O",6,0)))

Excel returning a False response

=IF(B12<>"",(IF(U12="Subscription","Subscribe",IF(U12="T.E.H.","Subscribe",IF(U12="ESA","Subscribe",IF(U12="Perpetual","Buy",IF(U12=" "," ")))))))
I get a "False" value in the cell with this formula in it when the value in U12 is not one of the options and I want to get a blank
Appreciate any help
Thanks
Change this: IF(U12=" ", " ") to this: IF(U12=" ", " ", ""). Here's a demo in Google Sheets, but the formulas are the same.
https://docs.google.com/spreadsheets/d/10iFqq0PNt9VhGKMPLCxsI1df0x4nDSxCaCGSdEEktO8/edit#gid=0
However, I don't think this is exactly right. For one thing, it looks like this clause:
IF(U12=" ", " ")
is only there to try to generate the blank you are looking for. If that's the case, then change it to:
IF(U12=" ", " ", "")
However, I think I would probably use some array constants, something like this:
=IF(B12<>"", CHOOSE(SUM(--(U12={"Subscription","T.E.H","ESA"})) + IF(U12="Perpetual", 2) +1, "", "Subscribe", "Buy"))
To break this down a little, let me reformat so it's easier to see:
=IF(
B12 <> "",
CHOOSE(
SUM(--(U12={"Subscription","T.E.H","ESA"})) +
IF(U12="Perpetual", 2) + 1
"", "Subscribe", "Buy"
)
)
I'm going to use CHOOSE, which takes an index number N and a list of choices, and it returns the Nth element in the choice list. To generate the index, I'm going to use a couple of techniques. First look at this:
U12 = {"Subscription", "T.E.H", "ESA"})
This is going to test U12 against all of the choices in the list, and return an array of TRUE/FALSE values. If U12 matches any of the elements in the array constant, then one of those values will be TRUE. We use -- to coerce that array from TRUE/FALSE to 0/1, and then we use SUM to get the array into a single value. It will either be 0 if U12 doesn't match any of the options, or 1 if it does.
Then I'm going to use a standard IF to check if U12 = Perpetual, and return 2 if it does. Adding that result to the previous sum will give us a final number that is either 0, 1 or 2.
CHOOSE is 1 indexed, meaning that it expects the index to be 1 or greater, so we add 1 to the number we just generated and pass it to CHOOSE along with a list of options.
The advantage here is that if the Subscribe options change you can just change the list, instead of having to alter a bunch of nested IFs. Also, if you need to support multiple buy options, you can do it with a similar construction:
SUM(--(U12 = {"Subscription", "T.E.H", "ESA"})) +
IF(SUM(--(U12 = {"Perpetual", "Buy Now"})), 2) + 1
and if you needed to add return values just keep extending:
CHOOSE(
SUM(--(U12 = {"Subscription", "T.E.H", "ESA"})) +
IF(SUM(--(U12 = {"Perpetual", "Buy Now"})), 2) +
IF(SUM(--(U12 = {"Release", "Dropping"})), 3) + 1,
"", "Subscribe", "Buy", "Sell"
)
If you think this is something that might need to be maintained or the options might change, I would set it up like this, as opposed to nested IFs.
Is this a little clearer?
=IF(B12=""," ",IfError(VLookup(U12,{"ESA","Subscribe";"Perpetual","Buy";"Subscription",Subscribe";"T.E.H.","Subscribe"},2,false)," "))
This is really just a table lookup, hence the use of VLookup. The lookup array is a two dimensional array in curly brackets - the commas and semicolons are very important for defining a 2x4 array for VLookup. The IFError function tells how to return your desired " " result if the lookup fails.

How to code if else statement with odd numbers

I don't know how to do this in if else statement
I want to to write IF the user input is odd number THEN Msgbox "Not valid" ELSE solve
That'll be:
If Value Mod 2 Then
MsgBox "Not valid."
Else
' Solve.
End If
when it comes to odd and even we use the mod which gives us the remainder, if the remainder is 0 the number is even and if it's 1 then it's odd hope this helps:)

'The formula you typed contains an error' in Excel Nested IF formula

I'm trying to create an excel formula for the below logic:
If ((Value in A1 - 250000) >= 250000){
Then Value in A2 = (0.05*(250000))
}
Else{
If ((Value in A1 - 250000) <= 0){
Then Value in A2 = 0
Else{
Value in A2 = (0.05*(Value in A1-250000))
}
}
Below is the formula I wrote:
=IF(((A1-250000)>=250000), ((0.05*(250000))), IF (A1-250000)<=0, 0, (0.05*(A1-250000)))
And Excel throws following error
The formula you typed contains an error
Any help with identifying the error is appreciated.
I think this reproduces your logic:
=IF(A1>500000,0.05*250000,0.05*MAX(A1-250000,0))
or maybe even:
=0.05*MAX(0,MIN(A1-250000,250000))
although I agree that IFS might be more clear, but I think you need Office 365 for that function.
IFS is clearer:
=IFS(A1-250000 >= 250000, 0.05*250000, A1-250000 <= 0, 0, TRUE, 0.05*(A1-250000))
although if this is trying to compute something like a statistical measure, you could use an out of the box function like MEDIAN.
Reference: https://support.microsoft.com/en-us/office/ifs-function-36329a26-37b2-467c-972b-4a39bd951d45

Why I am getting FALSE for "=FALSE<=100" in excel

Hi I am Priya from India,
I am trying to get the logic in excel formula
=FALSE<=100
False will be considered as 0. if it is 0<=100 then expected output is TRUE.
But we are getting FALSE in the Microsoft Excel.
Why I am not getting True?
TRUE and FALSE can't be treated directly as numbers on Excel. However, they can be implicitly converted to numbers:
=(FALSE + 0) <= 100
Adding 0 to them does it.
The formula you mentioned in the comment, even though it seems to return a correct result - (10> = 50 AND 10 = <- 100) == FALSE, is basically incorrect, because excel calculates it as follows:
=(10>=50 & 10<=100)
=(10>="5010"<=100)
=(FALSE<=100)
= FALSE
If you want the numbers to be compared, you can use the following options:
Use the AND function:
=AND((10>=50),(10<=100))
Multiply the comparisons and check if the result is greater than zero
=(10>=50)*(10<=100)>0

Resources