Excel IF Statement - Multiple conditions in columns - excel

Excel screenshot
I want to run a logical test that will execute either of two pieces of code based on a boolean outcome in MS Excel.
I have attached a sample of data. I want to run a logical IF test that executes either of two other functions based on TRUE or FALSE if column A contains "February" and column B contains the word "Breakfast" - but both conditions have to be in the same row, and can appear more than once (just has to be greater than zero). This is the code I came up with:
=IF(AND(COUNTIF(A:A,"February")>0,(COUNTIF(B:B,"*Breakfast*")>0)),"Run this code","Runthatcode")
I'm currently learning programming and Excel so my knowledge is pretty limited right now.
Many thanks.
Fraser

Try using the COUNTIFS function to accomplish this.
=IF(COUNTIFS(B:B, "ValueA", C:C, "ValueB") > 0, Function1, Function2)

Related

multiple conditionals in excel is there a better function to use

I'm having a problem with my excel formula, the formula is supposed to basically be a bunch of if functions written out it looks like
If (h3< 1, H3+1),
If (h3>= 5 and H3<= 10, H3+2),
Else H3+3
I tried to put it into an excel formula based on what I saw online and some YouTube videos on if functions in excel but it's saying I added too many arguments. "Error: You've entered too many arguments for this function". Is there a better way to do this formula? Should I be using AND instead of multiple IF's? Does anyone have any advice or suggestions? Also any recommendations on how to improve with excel?
Here's my current formula:
'''
=IF(H3>10, H3+3,
IF(H3<=10, H3>=5, H3+2,
IF(H3<1, H3+1)))
'''
I expect for the formula to add either 1, 2, or 3 based on H3.
You have too many arguments in the second nested if statment
=IF(H3>10, H3+3,IF(H3<=10, H3>=5, H3+2, IF(H3<1, H3+1)))
If statements have 3 conditions
1) the logic statement
2) what to do if the logic statement is true
3) what to do if the logic statement is false
In your second in your second if statement you have 4 conditions - it looks like 2 logic statments H3<=10 AND H3>=5. If you want to use both of those logic statements, you will need to add in AND()
=IF(H3>10, H3+3,IF(and(H3<=10, H3>=5), H3+2, IF(H3<1, H3+1)))
Additionally, in this scenario, you only have 2 conditions for your final IF statement. You need to add in a final value for when all logic statements are false.
=IF(H3>10, H3+3,IF(and(H3<=10, H3>=5), H3+2, IF(H3<1, H3+1, "ADD VALUE FOR WHEN FALSE")))
Also be careful if you have blank cells, you might not get the answer you're looking for if H3 is ever blank.

Combining multiple IF-statements into one formula

I am constructing a formula to act as an extra 'control cell' for my excel worksheet.
The if statements in text with the expected result:
If D2=0 and E2=0 and F2=0 =>""
If D2=0 and E2>0 and F2=0 =>"m of m2"
If D2>0 and E2>0 and F2=0 =>"m2 of m3"
If D2>0 and E2>0 and F2>0 =>"m3"
If D2>0 and E2=0 and F2>0 =>"m2"
If D2=0 and E2>0 and F2>0 =>"m2 of m3"
If D2=0 and E2=0 and F2>0 =>"m"
If D2>0 and E2=0 and F2=0 =>"m"
I'll converting this formula to vba afterwards, but my knowledge of vba is pretty limited so I like to start with just the excel formula.
Thanks in advance.
*edit: so far the formula always returns "m3" so it acts like all the cells are >0 even if they are empty/have a 0 value.
Formula so far (it's in dutch so als=if)
=ALS(D3=0&E3=0&F3=0;"";ALS(D3=0&E3>0&F3=0;"m of m2";ALS(D3>0&E3>0&F3=0;"m2 of m3";ALS(D3>0&E3>0&F3>0;"m3";ALS(D3>0&E3=0&F3>0;"m2";ALS(D3=0&E3>0&F3>0;"m2 of m3";ALS(D3=0&E3=0&F3>0;"m";ALS(D3>0&E3=0&F3=0;"m";""))))))))```
One way to interpret your table of results is that the value is equal to 0 or its not. your table does not cover the possibility of of values being less than 0. With this understanding one possible NESTED IF function would be:
=IF(D2=0,IF(E2=0,IF(F2=0,"","m"),IF(F2=0,"m of m2","m2 of m3")),IF(E2=0,IF(F2=0,"m","m2"),IF(F2=0,"m2 of m3","m3")))
Alternatively in excel you could use the CHOOSE function. Since each result is unique and its based based on binary results you could use the following formula to generate an index number from 1 to 8:
1+(F2>0)+(E2>0)*2+(D2>0)*4
Drop that in a CHOOSE function and its much more shorter manageable then nested IF. It could look as follows:
=CHOOSE(1+(F2>0)+(E2>0)*2+(D2>0)*4,"","m","m of m2","m2 of m3","m","m2","m2 of m3","m3")
now not being a VBA guru either, I am not sure how CHOOSE would translate over to VBA. But that would be another question!
UPDATE: ALTERNATE IF function
=IF(AND(D2=0,E2=0,F2=0),"",IF(AND(E2=0,D2<>F2),"m",IF(AND(D2=0,E2>0,F2=0),"m of m2",IF(AND(E2>0,D2<>F2),"m2 of m3",IF(AND(D2>0,E2=0,F2>0),"m2","m3")))))
There are many ways to go through the logic. In this case I was able to group the IF functions by results.

Define Status depending on Criteria

I have advanced Excel/Google Sheets skills. I have more of a conceptual question. I am happy with any solution (Excel or for Sheets, no difference for me).
I have a sheet where various coworkers have access and work with. It is used to define which product needs to go through which steps. Then when a part of a job is done, the status of the product is changed depending on criteria.
You can also think of it as projects and the status of a project.
The 3 examples shows how the data is input by the workers. Sometimes, the "No" cells are empty, sometimes they have a "No", sometimes for the same product, one criterion is empty, the other has a "No".
If I do a nested IF formula, I would have to create 32 of them (I believe, since its 5 criteria with each 2 options).
Obviously I can do that. I was wondering anyone has a better solution for me? Something more practical.
Thanks in advance!
Based on the data you've provided, it looks like your statuses are based on the number of Yes's in the input columns. Also you don't have a status shown for zero Yes's so I'll make an additional for that.
Given that assumption you can use a combination of the COUNTIF function (to count the Yes's), and the IFS function (to manage nested Ifs better) to drastically reduce the size of your function.
To make this cleaner I suggest you add a column and hide it containing: =COUNTIF([InputCriteria1to5Range],"Yes")
For the next formula assume the formula above is in B2. In your status column put the following:
=IFS(B2=5, Status1, B2=4, Status2, B2=3, Status3, B2=2, Status4, B2=1, Status5, B2=0, Status6)
Solution: Thanks to all for your help, I ended up firstly, creating ALL scenarios. This was actually the most complex part. See https://www.mrexcel.com/forum/excel-questions/654871-how-generate-all-possible-combinations-two-lists-without-macro.html (Answer from "Tusharm") where I had to repeat this process 5 times to have all possible outcomes. In the end, there were 192 combinations.
Then, I assigned a status for each combination.
Finally, for each product/row, I created another column where I concatenated the different criteria so that it looks exactly like my above combinations. Then finally index match the concatenated criteria to my combinations.

How to use multiple separate formulas in a single "IF" in Excel?

I have a basic understanding of excel formulas work and have used this site many times to broaden my knowledge, however, I'm stuck on the below and I'm hoping someone can assist me.
I'm trying to create a formula to work out if a KPI has been met. I have 3 separate formulas that I need to combine into one.
=IF(AND(E2="1",S2>0.041667),"YES","NO")
=IF(AND(E2="2",S2>0.125),"YES","NO")
=IF(AND(E2="3",S2>0.25),"YES","NO")
How do I do this?
I think you just need to use an OR to combine them. See below:
=IF(OR(AND(E2="1",S2>0.041667), AND(E2="2",S2>0.125), AND(E2="3",S2>0.25)) ,"YES","NO")
The OR requires at least one argument to be true, so the statement will evaluate to TRUE if at least one of the the AND statements returns true.
A bit simplified with the CHOOSE function (results in #VALUE! error if E2 is not 1, 2, or 3) :
=IF(S2 > CHOOSE(E2, 0.041667, 0.125, 0.25), "YES", "NO")

Excel Serial If statements

I'm new to Excel, and I'm struggling with a formula. Essentially, what I'm looking for is to filter a cell through a set of procedures using a formula (this part isn't strict).
For example
Let's say I have a cell, A1. I'm trying to perform different calculations on this based on whether it is between a certain range of values. The problem is, it can be within several ranges.
Pseudo-Code representation
If(A1 > 187.5) {
// Run some code here.
}
If(A1 > 150) {
// Run some code here.
}
NOTE : The above example is only to illustrate the logic of sequential if statements.
Note that I Do not want a nested If statement. I'm just trying to run the same value through various checks. How do I do this in an Excel formula?
The best I can come up with is something like the following.
=(A1>187.5)*<some expression>+(A1>150)*<some expression>+....
The result of this will be some single value. (The straightforward way to get multiple values is to have the individual terms in separate cell.
If you want the result to reflect one among several mutually exclusive outcomes, then you would want to go with:
=(A1>187.5)*<some expression>+(A1>150)*(A1<=187.5)*...etc.
There are many ways to achieve this. One way is to use nested conditions like this:
=IF(Something, do something, IF(something else, do something, do something))
This is good if you want to condensate the formula a bit but arguably leads to more cluttered formulas. According to the FAST-Standard organization, those cases of nested conditions should be replaced by the use of flags. The most simple case would be, for example, where you would be looking for a rebate percentage according to a sales amount. In multiple cells you would have IF conditions evaluating to true only if the value matches that specific range. Then, your formula can be as simple as a SUMPRODUCT of your flags with your rebates percentages.
This is one example, but it can be applied to other cases very well too.
if there is a relationship between the numbers your checking for its very likely you can use
=CHOOSE(FLOOR(A1/160,1)+1,"<160",">160")
Which would put your 150 in the first and leave your 185 in the second

Resources