excel if and multiple and - excel

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","???"))))

Related

Writing to a new Excel column based on other columns

I have an Excel table like this shown below. There are some empty cells under each header F1, F2, F3, F4, and F5.
Path F1 F2 F3 F4 F5 NewPath
image1.png 1 0 -1 1
image2.png 1 -1 1
image3.png 1 0 1 -1 1
image4.png 1 0 0 1
image5.png 1 1 1 -1
image6.png 1 -1
image7.png -1 1 1 0
image8.png 0 1 1
I have to write the values in column 1 (under the header "Path") to the column (under the header "NewPath") only if the following conditions are satisfied:
There should be a 1 in F3 and not any other value, i.e., 0, -1, or empty field.
There should not be a 1 or -1 in any of F1, F2, F4, and F5.
Whatever cell you need to write to, you can use an if/and statement. Assuming that the word "Path" is in cell "A1" this might look like the following:
=if(and(d2=1,b2<>1,b2<>-1,c2<>1,c2<>-1,e2<>1,e2<>-1,f2<>1,f2<>-1),a2,"Incorrect Value Found")
Then, just copy down the formulas. I put in "Incorrect Value Found" for those instances that do not satisfy your conditions, but this could be anything. If you need to cut those out after the fact, you could do so by filtering, ordering them to the bottom, or a slicer on a pivot table.
Hope this helps. Let me know if I missed the mark on my understanding of the question.
Would something like
=IF(AND($D2=1,COUNTIF($b2:$f2,"<>0")>=1),$A2,"")
Work for you?
There is no match in the input data based on your requirements. I modified (highlighted cells, see screenshot below) the input data so we can have at least one match for testing purpose.
In cell G2 put the following formula:
=LET(f3Cond, $D$2:$D$9=1, f1f2f4f5Cond,
MMULT(ABS(CHOOSECOLS(B2:F9,{1,2,4,5})),{1;1;1;1})=0,
allCond, IFERROR(XMATCH(f3Cond * f1f2f4f5Cond,1),""),
MAP(allCond, A2:A9, LAMBDA(a,b,IF(a=1, b, "")))
)
and here is the output:
Explanation
We use LET to define intermediate calculations. The variable f1f2f4f5Cond represents the condition for F1, F2,F4 and F5 columns.
MMULT(ABS(CHOOSECOLS(B2:F9,{1,2,4,5})),{1;1;1;1})=0
We use CHOOSECOLS to select the specific columns from range B2:F9 we need to evaluate the conditions. We need to exclude 1, -1, so we use ABS to ensure MMULT returns the sum of all 1's per row. We can use MMULT for this purpose because the only values we have are 0,1 and empty. All the conditions are valid if the total number of 1's is 0.
Note: As an alternative you can replace the MMULT calculation with the following:
= BYROW(ABS(CHOOSECOLS(B2:F9,{1,2,4,5})),
LAMBDA(a, SUM(a)=0))
We use XMATCH to identify the rows where all the conditions are met.
IFERROR(XMATCH(f3Cond * f1f2f4f5Cond,1),"")
#N/A values are converted to empty string. The array allCond has 1 only where all conditions are met, otherwise empty string.
Finally we use a MAP function to populate the Path column value from the rows that matches the conditions, otherwise an empty string.

Excel - How can I set up a calculation in 1 cell, based on the text in 1 cell and a number in another?

I have a text in cell D2 and a number in E2. If the number in E2 is less than 10, I need to divide E2 by 10 and then times it by a particular value, based on the text in D2. I then need that new number or text in H2.
D2 has a drop down with 7 options.
If D2 = "Consultant (+7 Years Experience)" and E2 is less than 10 (say 6 for example), I would need to do 34 x (6/10) and have it calculated into H2.
And if D2 = Consultant 0-6 Years Experience and E2 = 6, it would be 32 x (6/10)
Here's the solution I'd go for:
H2 cell:
=IF(E2<10, E2/10,
IF(D2 = "Consultant (+7 Years Experience)", 34*E2/10,
IF(D2 = "VALUE2", CALCULATION,
*etc. based on the number of options in the dropdown*
Please note, you need a number of brackets at the end that corresponds to the number of conditions used. What's going on here is that we have nested conditions roughly equivalent to the following:
IF (COND1 TRUE, DO THIS,
ELSE IF (COND1 FALSE AND COND2 TRUE, DO THIS,
*etc.*
Here's more documentation on IF: link.
Your final condition's FALSE value is optional.

Excel formula if returns false

I have the following formula:
=IF(I2=0;IF(D2="*CONTADO*";K2=I2;K2=7);K2=I2)
For some reason it returns FALSE, where it should copy the value of I2 or else make it 7.
Aside of that, I don't know if the right way to make a "contains" is just asterisk inside the quotes.
EDIT:
formula now reads as:
=IF(I2=0;IF(OR(ISNUMBER(SEARCH("ALBARAN";D2));ISNUMBER(SEARCH("CONTADO";D2)));I2;7);I2)
It returns false when it matches the searched words in the cells.
I did a small test with
=ESNUMERO(BUSCAR("CLAVIJA";D3))
(to clarify it, Spanish Excel translates every formula name (sigh). ESNUMERO is ISNUMBER and BUSCAR is SEARCH. I've been translating it the whole time for your understanding.)
and did an auditory of the formula. It gets a #N/A when finding "CLAVIJA" even in the cell reads just like that. The value of D3 is "CLAVIJA MULTIPLE 10-16A T.T.LA".
Here in image you can see, you can achieve your desired results, I have done with 3 test cases
FORMULA TO DO =IF(I2=0,IF9D2="CONDTADO",12,7),I2)
B2 0 D2 *CANTADO* I2 0 K2 0 L2 OUTER AND INNER IFS ARE TRUE
B3 3 D3 *CANTADO* I3 3 K3 3 L3 0 OUTER IF IS FALSE
b4 7 D4 *CANTAD* I4 0 K4 7 L4 0 OUTER IF IS TRUE BUT INNER IS FALSE
Solved by replacing SEARCH by FIND.

Summation of an array of max values in excel?

Suppose I have the following data in cells A1:A3
A1 = 1
A2 = 3
A3 = 5
I'd like to write a formula that sums the difference between the number in the cell and 2. If the difference is negative, then take 0. I tried the following CSE/array formula:
{=sum(max(A1:A3-2,0))}
Excel evaluates the formula as follows:
sum(max({1-2,3-2,5-2},0)) = sum(max({-1,1,3},0)) = sum(max(-1,1,3,0)) = sum(3) = 3
I'd like to write a formula that is evaluated as follows:
sum({max(-1,0),max(1,0),max(3,0)}) = sum({0,1,3}) = 4
Obviously one approach to this problem is to carry out a second computation in column B such that:
B1 = max(A1-2,0) = max(-1,0) = 0
B2 = max(A2-2,0) = max( 1,0) = 1
B3 = max(A3-2,0) = max( 3,0) = 3
then my target formula is:
= sum(B1:B3) = 4
However, I'd like to know: is there a way to do this in a single cell using array formula?
Thanks!
How about this? Instead of trying to use MAX, just use SUMPRODUCT. If the difference is negative, A1:A3-2>0 evaluates to FALSE, which is equivalent to multiplying the difference by 0.
=SUMPRODUCT((A1:A3-2)*(A1:A3-2>0))

from LOOKUP function to VLOOKUP

I'm trying to use VLOOKUP excel function instead of LOOKUP.
I've read VLOOKUP is well optimized but I'm not able to adjust it.
Any help please?
Following function return:
1 if first condition met is >
-1 if first condition met is <
=LOOKUP(2,1/((E1:E9>E10)-(E1:E9<E10)))
Scope of function is: looking to E10 value, searching on range E1:E9 starting from bottom to top, if firstly appear a number > or < of E10, returning +1 or -1
Example 1
E1 = 6
E2 = 5
E3 = 5
E4 = 4
E5 = 6
E6 = 6
E7 = 5
E8 = 8
E9 = 8
If E10 = 8
Result is -1 because first value found is smaller than E10 (starting from E9 and going up)
If E10 = 7
Result is 1 because first value found is bigger than E10 (starting from E9 and going up)
??
=VLOOKUP(2,1/((E1:E9>E10)-(E1:E9<E10));1)
or any other function instead of LOOKUP?
Previous supposed solution works correctly
=VLOOKUP(2,1/((E1:E9>E10)-(E1:E9<E10));1)
but formula needs to be entered with:
CTRL+SHIFT+ENTER
I've tried with MATCH but to me result to don't work correctly.
Any other ideas?
Returning to my first function:
=LOOKUP(2,1/((E1:E9>E10)-(E1:E9<E10)))
I've scomposed it, to understand how it works, to find others possible solutions.
Firstly Excel convert my condition into TRUE and FALSE
IF E10=8
=LOOKUP(2,1/((FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE)-(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE)))
Next it converts TRUE and FALSE into 1 and 0
=LOOKUP(2,1/((0,0,0,0,0,0,0,0,0)-(1,1,1,1,1,1,1,0,0)))
Next it makes "-" operation obtaining:
=LOOKUP(2,1/(-1,-1,-1,-1,-1,-1,-1,0,0))
Next it converts into arrays:
=LOOKUP(2,{-1,-1,-1,-1,-1,-1,-1,#Div/0!,#Div/0!},ROW(E1:E9))
Next converts also ROW(E1:E9) into arrays obtaining:
=LOOKUP(2,{-1,-1,-1,-1,-1,-1,-1,#Div/0!,#Div/0!},{1,2,3,4,5,6,7,8,9})
To conclude looks from bottom to top of range, searching for a value close to 2, returnig -1 because E7=5 and is smaller than E10=8
So now, understanding how Excel elaborates is possible to use following function to obtain arrays:
=INDEX(1/((E1:E9>E10)-(E1:E9<E10)),0)
resulting in the same:
{-1,-1,-1,-1,-1,-1,-1,#Div/0!,#Div/0!}
and using previous result combined with VLOOKUP, to get same result of LOOKUP function, but accepting it whitout CTRL+SHIFT+ENTER that was my goal
=VLOOKUP(2,INDEX(1/((E1:E9>E10)-(E1:E9<E10)),0),1)

Resources