Can anyone show me how to write a chart to figure out how to write a nested if/and formula?
Can anyone show me how to write a chart to figure out how to write a nested if/and formula?
could you explain what you mean by show me how to write a chart to figure out how to write a nested if/and formula?
if/and statements go like this... =if(and(A2=condition 1,B2=a condition[add more and statements if you want]),then do this, otherwise do that) The thing to remember is that both conditions have to exist for the formula to return a positive result, else you get the otherwise do that result. For if/or either condition can exist for your positive result.
beyond that you'll need to provide more information.
Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
Sam Capricci
Here is an example with 2 conditions. You can have many more conditions but the exact number depends upon what version of Excel you're using.
=IF(AND(A1>=10,A1<=25),"Yes","No")
We're testing that the number in cell A1 is greater than or equal to 10 AND less than or equal to 25. Typically, we would define that as being between 10 and 25 (inclusive).
If ALL the conditions are met return Yes otherwise, return No.
Last edited by Tony Valko; 12-25-2015 at 07:46 AM. Reason: reworded for clarity
Biff
Microsoft MVP Excel
Keep It Simple Stupid
Let's Go Pens. We Want The Cup.
Referring back to your previous IF/AND/THEN thread, list the conditions and relevant outcomes as you did there with your first example, and decide on a final 'ELSE' outcome for anything that doesn't match up with any of the specified criteria.
Start looking for common factors to pair up criteria with results so that you don't have to test the same criteria multiple times.
If not sure, ask us for help, generally speaking, if you need more than 3 IF's in one formula, then there probably a better way to do the job.
The last line of the formula that I provided for you in post #23 of that thread is a compact equivalent of using IF(AND( 8 times!
I'm trying to figure out how to write a nested IF/AND formula with lots of variables so I don't have to keep asking people how to write them. I KNOW this post is similar to another post but PLEASE DON'T DELETE IT.
Here's my end goal: copy and paste the 12 cells from each example (there are 18 examples) into the twelve cells that start at J2 and end at M4. I'm looking to write a nested IF/AND formula that will give the "expected value" listed next to each example. I have written a formula that can satisfy examples 1&2 and 3&4 individually but I don't know how to successfully combine the two. From there I don't even know how to write examples five through eighteen.
So my question is THIS:
Is there a way to write out on a sheet of paper all the possible outcomes and then use that as a guide to write a nested IF/AND formula that satisfies my requirements? If so, what would that diagram look like?
Highlighted in yellow are all the values that are pertinent to determining the "expected value for that example".
Last edited by quibilty; 12-25-2015 at 08:15 PM.
How do you want the answer shown? I am thinking taht a countifS() would be fgar better suited to this than nested if()
For instance...
=COUNTIFS($D:$D,$J2,$E:$E,"W",$F:$F,"<=-151",$G:$G,100)
gives 3
I know that is not what you want, but we can work on that
1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
2. If your question is resolved, mark it SOLVED using the thread tools
3. Click on the star if you think someone helped you
Regards
Ford
I don't know much about countifs(). As far as how I want the answer shown the value listed under "expected value" is what I'm trying to get. So a formula written in H2 and then copy/pasted down in H to give the value listed.
Is there a way to SHOW how one creates a countifs() formula?
=countifS() is just an extention of countif(), the syntax is...
=countif(criteria range, criteria)
or
=countifS(criteria range1, criteria1,criteria range2, criteria2,criteria range3, criteria3................)
In my example, I did a test for
$D:$D,$J2,............count 1 in column D
$E:$E,"W",............count "W" in E
$F:$F,"<=-151", ....count <=-151 in column F
$G:$G,100)............count how many 100 in column G
so when all these are combined, it counts entries that match all of those criteria in each row
=countifS() is just an extention of countif(), the syntax is...
=countif(criteria range, criteria)
or
=countifS(criteria range1, criteria1,criteria range2, criteria2,criteria range3, criteria3................)
In my example, I did a test for
$D:$D,$J2,............count 1 in column D
$E:$E,"W",............count "W" in E
$F:$F,"<=-151", ....count <=-151 in column F
$G:$G,100)............count how many 100 in column G
so when all these are combined, it counts entries that match all of those criteria in each row
Ah, I see. That won't work for what I'm looking for. I'm looking for ONE value in H and that value will either be:
(using D2:G4 as an example)
0, G2, G3, G4, G2+(G3*2), G2+(G4*2), G3+(G4*2), or G2+(G3*2)+(G4*3)
Oh, and I really messed up in my excel example. I can see why people were having a hard time helping me. So for each example listed pretend all 18 examples are copied/pasted into D2:G4 and that the "expected value" and "how expected value was calculated" are to the right. Also, notice that the yellow highlights have changed.
Last edited by quibilty; 12-25-2015 at 09:18 PM.
What if we tried this instead: in column H of this worksheet I copied/pasted a formula that was created for me by someone else that is SIMILAR to what I want. Can someone show me how to write that formula as flow chart or diagram so I can reverse engineer that formula and thus learn how to create the formula I'm looking for?
Or maybe this is easier? Here are all the IF/AND formulas that I need to use (only without the "value if false" values). Is there a way to combine them into one formula?
#1 IF(AND(D2=1, E2=W, F2>=-150)),G2
#2 IF(AND(D2=1, E2=W, F2<-150)),0
#3 IF(AND(D2=1, E2=L, F2<-150, D3<>2)),0
#4 IF(AND(D2=1, E2=L, F2>=-150, D3<>2),G2
#5 IF(AND(D2=1, E2=L, F2>=-150, D3=2, E3=W, F3>=-150)),G2+(G3*2)
#6 IF(AND(D2=1, E2=L, F2>=-150, D3=2, E3=W, F3<-150)),G2
#7 IF(AND(D2=1, E2=L, F2<-150, D3=2, E3=W, F3>=-150)),G3
#8 IF(AND(D2=1, E2=L, F2<-150, D3=2, E3=W, F3<-150)),0
#9 IF(AND(D2=1, E2=L, F2>=-150, D3=2, E3=L, F3>=-150, D4=3, F4>=-150)),G2+(G3*2)+(G4*3)
#10 IF(AND(D2=1, E2=L, F2>=-150, D3=2, E3=L, F3>=-150, D4=3, F4<-150)),G2+(G3*2)
#11 IF(AND(D2=1, E2=L, F2<-150, D3=2, E3=L, F3>=-150, D4=3, F4>=-150)),G3+(G4*2)
#12 IF(AND(D2=1, E2=L, F2<-150, D3=2, E3=L, F3<-150, D4=3, F4<-150)),0
#13 IF(AND(D2=1, E2=L, F2>=-150, D3=2, E3=L, F3<-150, D4=3, F4>=-150)),G2+(G4*2)
#14 IF(AND(D2=1, E2=L, F2<-150, D3=2, E3=L, F3<-150, D4=3, F4>=-150)),G4
#15 IF(AND(D2=1, E2=L, F2>=-150, D3=2, E3=L, F3>=-150, D4<>3)),G2+(G3*2)
#16 IF(AND(D2=1, E2=L, F2<-150, D3=2, E3=L, F3>=-150, D4<>3)),G3
#17 IF(AND(D2=1, E2=L, F2<-150, D3=2, E3=L, F3<-150, D4<>3)),0
#18 IF(AND(D2=1, E2=L, F2>=-150, D3=2, E3=L, F3<-150, D4<>3)),G2
Last edited by quibilty; 12-26-2015 at 04:39 AM.
I suggest you focus on the conditions that will lead to an outcome other than 0, then make 0 the final ELSE outcome.
Ali
Enthusiastic self-taught user of MS Excel who's always learning!
Don't forget to say "thank you" in your thread to anyone who has offered you help.
You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.
Forum Rules (updated August 2023): please read them here.
OK. That's good advice, but I'm still not sure where to start... Is there a way to write out this logic and then create an easy chart that will help me create the formula?
You've done that above, really. Try taking each line, adding a comma at the end and then pasting the next IF statement. Excel should help you with the parenthesis at the end of the formula.
The IF formula doesn't have to be in any specific order???
AliGW, I can't believe that worked, but it did!
=IF(AND(D2=1, E2="W", F2>=-150),G2, IF(AND(D2=1, E2="W", F2<-150),0,IF(AND(D2=1, E2="L", F2<-150, D3<>2),0,IF(AND(D2=1, E2="L", F2>=-150, D3<>2),G2,IF(AND(D2=1, E2="L", F2>=-150, D3=2, E3="W", F3>=-150),G2+(G3*2),IF(AND(D2=1, E2="L", F2>=-150, D3=2, E3="W", F3<-150),G2, IF(AND(D2=1, E2="L", F2<-150, D3=2, E3="W", F3>=-150),G3,IF(AND(D2=1, E2="L", F2<-150, D3=2, E3="W", F3<-150),0,IF(AND(D2=1, E2="L", F2>=-150, D3=2, E3="L", F3>=-150, D4=3, F4>=-150),G2+(G3*2)+(G4*3),IF(AND(D2=1, E2="L", F2>=-150, D3=2, E3="L", F3>=-150, D4=3, F4<-150),G2+(G3*2),IF(AND(D2=1, E2="L", F2<-150, D3=2, E3="L", F3>=-150, D4=3, F4>=-150),G3+(G4*2),IF(AND(D2=1, E2="L", F2<-150, D3=2, E3="L", F3<-150, D4=3, F4<-150),0,IF(AND(D2=1, E2="L", F2>=-150, D3=2, E3="L", F3<-150, D4=3, F4>=-150),G2+(G4*2),IF(AND(D2=1, E2="L", F2<-150, D3=2, E3="L", F3<-150, D4=3, F4>=-150),G4,IF(AND(D2=1, E2="L", F2>=-150, D3=2, E3="L", F3>=-150, D4<>3),G2+(G3*2),IF(AND(D2=1, E2="L", F2<-150, D3=2, E3="L", F3>=-150, D4<>3),G3,IF(AND(D2=1, E2="L", F2<-150, D3=2, E3="L", F3<-150, D4<>3),0,IF(AND(D2=1, E2="L", F2>=-150, D3=2, E3="L", F3<-150, D4<>3),G2,0))))))))))))))))))
Glad to have helped! There may well be ways of writing a shorter, more efficient formula, but this is a start for you.
One way to shorten it would be to test a single common condition first, for example, each of your individual formula contains D2=1, so by testing that first, you could remove it from each of the AND functions, shortening the formula quite a bit
=IF(D2=1,your mega formula with D2=1 removed from each instance of AND(),0)
Likewise, E2 should only = W or L so you could split the formula the same way again and remove that part from the AND functions, shortening it again, given that this only leaves one remaining condition in the first 2 AND functions, you could remove AND entirely from those, and one of the IF's as well.
Hopefully that makes sense, have a play with it and see what you can come up with.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks