I have two numbers A1 and B1, and on C1 I want to do the following.
If the number in A1 satisfies a < A1 <= b AND c <= B1 < d, then I want C1 to show success.
If a < A1 <= b is satisfied but not c <= B1 < d, I want C1 to show TOO LOW.
And similarly if c <= B1 < d is satisfied but a < A1 <= b is not, I want C1 to show TOO HIGH.
I initially wanted to use the IF function but I was not quite sure how to split them into cases and I'm sure there is a way. I'm just not too familiar with Excel words and did not know what I am trying to do is called so I could not look for it on my own...
It would be of great help.
Nested if statements along with And is the way to go. Something like:
=IF(AND(1<A1,A1<5),IF(AND(4<=B1,B1<10),"Success","Too Low"),IF(AND(4<=B1,B1<10),"Too High","Failure"))
I arbitrarily picked a = 1, b = 5, c = 4, d = 10 in your problem description and decided that the cases where both conditions fail should be called, well, "Failure"
The logic is as follows, first the condition on A1 is tested. If it is satisfied then the condition on B1 is tested. If it is also satisfied, then "Success" is returned, otherwise "Too Low". At this stage we have taken care of what to do if the condition on A1 is satisfied. If it isn't -- we move on to the Else part of the outer if statement (the second half of the overall formula. We again check B1. If it is true and we reach this part of the formula, we know that we should return "Too High", on the other hand, if B1 still fails the condition and A1 fails it as well, the formula reports a failure.
Related
Column A contains dates. Column B contains dates and text values.
I'd like to write a formula that counts everything where (A:A <= DATE) AND (B:B > DATE OR B:B = "TextValue")
I know you can incorporate OR into countif using a formula like SUM(COUNTIF(A:A,{value1, value2})), but I have too many date values and want to use the > operator in the OR part.
I know this is a weird one with dates and text in the same column. Any help is appreicated.
I assume you want to count the number of rows that satisfy all the logical condition: A AND (C OR D), where each letter represents a logical condition. You can use in G2 the following:
=SUMPRODUCT( --(B2:B5<=E2),
--((--(C2:C5 > E2) + (--(C2:C5 = DATEVALUE(E4)))) > 0) )
or using LET function to represent better each conditions:
=LET(cond1, --(B2:B5 <= E2), cond2, --(C2:C5 > E2),
cond3, --(C2:C5 = DATEVALUE(E4)),
SUMPRODUCT(cond1, --((cond2 + cond3) > 0))
)
Here is the output:
The first row satisfies cond1, and the last row satisfies cond3.
Since you indicated the last condition is against a text value (E4) we need to convert it to a date using DATEVALUE.
SUMPRODUCT is expecting numeric values, so each logical condition needs to be converted to 1,0 values via --() operator. The OR condition is establish as a sum of two binary values and it should be greater than 0.
You can not use COUNTIFS in a scenario like this, because each criteria represents a simple comparison condition such as: "<="&E2 (for cond1 for example) internally it checks the condition: B2:B5 <= E2, i.e. a single logical condition where the left hand side appears only once. For an OR condition you need two logical conditions (i.e. OR(rng < a, rng > b)). In order to count a row all the conditions must be satisfied (logical AND), so there is no way to consider an OR condition with this function.
I am trying to write an Excel function in order to compare the values of two columns and write in a third column a specific value, dependent of that comparison. The conditions that need to be simultaneously met are the following:
IF A1 = 0 AND B1 = 1 THEN C1 = 2 IF A1 = 0 AND B1 = 2 THEN C1 = 1 IF A1 = 2 AND B1 = 1 THEN C1 = 3 IF A1 = 2 AND B1 = 2 THEN C1 = 4
Is it possible to achieve this with nested IF's in Excel?
Many thanks
So, based on what you state, this:
=if(and(a1=0,b1=1),2,if(and(a1=0,b1=2),1,if(and(a1=2,b1=1),3,if(and(a1=2,b1=2),4,"check"))))
Proving most cases:
What I would do, is to externalize those conditions. It helps you (and everyone else) whenever
your boss wants to know how your are calculating this specific value --> you simply show her the condition table (no need to look into the formula)
your boss (or the data itself) wants you to add another condition --> you simply add a new row to the conditions table (no need to make the formula longer)
...
The formula I use in Column C of the data table:
=IFERROR(FILTER(tblConditionC[C],(tblConditionC[A]=[#A]) *(tblConditionC[B]=[#B])),"no mapping")
This should do what you want:
=IF(A1=0,IF(B1=1,2,IF(B1=2,1,"Invalid Input")),IF(A1=2,IF(B1=1,3,IF(B1=2,4,"Invalid Input")),"Invalid Input"))
Ok, so I am trying to do something I thought was very simple, but it is turning out to be more complicated.
What I am trying to do:
Take a value through an if statement and return 1 or 0. But I want to be able to change the formula by changing values in cells and not editing the formula itself.
Example:
cell A1 = 41%
cell B1 = >
cell C1 = 40%
cell D1 = Formula with calculation
I want to create a formula that will tell me if that 41% is > than 40%, but if I change that > in B1 for a < (in a separate cell outside the cell with the formula) or I change C1 I want it to recalculate.
I have tried the following:
=IF(A1&B1&C1,1,0)
=IF(A1&INDIRECT(B1)&C1,1,0)
=IF(INDIRECT(A1)&INDIRECT(B1)&INDIRECT(C1),1,0)
all of these result in errors and I cannot figure out how to make it work. I am assuming it is taking the > and making it a string instead of a part of the formula.
Thanks for the help.
=COUNTIF( A1, B1&C1 )
... seems to do the trick, although converting C1 to text may give some rounding errors
An alternative would of course be to enumerate all the operations:
=--IFS( B1=">", A1>C1, B1="<", A1<C1 )
And add other operators as you come across them (NB the -- turns TRUE/FALSE into 1/0)
I need some help with an excel =if and formula
I have 4 different situations with 4 different outcomes
if cell N2 = 0 and A2 = "apple" then I need to print outcome AB
if cell N2 < 0 and A2 = "apple" then I need to print outcome CD
if cell N2 = 0 and A2 = "pie" then I need to print outcome EF
if cell N2 < 0 and A2 = "pie" then I need to print outcome GH
=IF(AND(N2=0, A2="apple"), "AB", "CD", IF(AND(N2=0, A2="pie"), "EF", "GH"))
according to excel there are to many arguments in this formula
Based on:
"Its just these values: equal to OR lower then zero and "apple" and "pie"
This should do:
=IF(N2=0,IF(A2="apple","AB","EF"),IF(A2="apple","CD","GH"))
IF is of the form
true/false statement, result if true, result if false
Your initial true/false bit is
AND(N2=0, A2="apple")
True bit
AB
False bit
CD
and that's your lot. You need to nest the next IF within the False bit.
This should work. If you have no other options, could probably be shortened. If your list gets any longer better to opt for a look-up table.
=IF(AND(N2=0,A2="apple"),"AB",IF(AND(N2=0,A2="pie"),"EF",IF(AND(N2<0,A2="apple"),"CD",IF(AND(N2<0,A2="pie"),"GH","???"))))
My workbook is a bit complicated, but the basic problem can be illustrated with a short example.
Let's assume that I have 5 cells in Excel: A, B, C, D, and E.
A = 0
B = 5 * A
C = 0
D = 10 * C
E = B + D
In the Excel Solver Function I select cell E as the objective that is to be maximised, and cells A and C as the variable cells. Furthermore, I add the constraint that cell E must not exceed 10, and the second constraint that cells A and C must be integers.
The ideal solution would be that the value in cell A should be 0, and the value in cell C should be 10. In the more complicated version of this problem, however, Excel cannot find the optional solution.
The way the current formulas look like I expect that Excel could find the right solution, if excel only used natural numbers to find the optimal solution. For example, Excel currently would look at the outcome for A = 0.01 and C = 9.99. Instead, Excel should strictly compare outcomes for variable choices such as A = 1 and C = 9.
How can I make the Excel solver function operate with natural numbers only?
I suggest you keep your current cells, and create a mirror set beside them. Each mirror cell will equal the rounded version of the original cell. ie: RoundedA will have the formula:
=ROUND(A,0)
Then when you do your data analysis, solve for the rounded version of those cells, with the changing variable being one of the "original" cells.
EDIT
As discussed below, you may need to 'trick' data validation into creating the values you want.
Assume A1 is going to be your "testing" data validation cell. B1 is a permanently blank cell. Set another cell, say, C1, equal to:
=randbetween(1,10)
This will create a random integer between 1 and 10. Set your "variable" cell to be equal to C10. So, your variable cell will always be a random number between 1 & 10 (or you could set "1" equal to the smallest number of your other variables, and "10" equal to the largest number of your other variables. This will create the scope needed to answer your question).
Then when you do data validation, make it try to get A1 = TRUE. Do this by figuring out what the 'test' condition is of your cells. Something like "when X = 0, I know that all my variables are correct". ie set A1 to:
=if(X=0,1,0)
Then do data validation by changing B1 (your blank, unrefered-to cell), waiting until A1 = 1. Does that make sense? It will turn C1 into the random cycling variable between LOWVALUE and HIGHVALUE, always using integers. Data validation will stop when A1 = 1 (which happens when some value X = 0). B1 will just spin uselessly until Data validation finds something (or it will stop after a few hundred tries if it finds nothing).
To get Solver to try larger increment divide the target cells by a large number and in such a way, each increment that solver tries is larger. (for example it changes the target cells by +-0.00001 - in that case divide the target cells by 100000 or more).