How to do a quadruple IF in excel - excel-formula

I would like to make an IF statement in Excel where if a certain cell equals to O, V, G or U another cell outputs 1, 2, 3 or 4 respectively.
I can't find any solution only, sorry.

There's probably a cleaner way to do this... but I'm not an excel expert.
If A1 is the cell you are checking to contain O V G or U:
=IF(A1="O", 1, IF(A1="V", 2, IF(A1="G", 3, IF(A1="U", 4, ""))))
The syntax of excel's if is: If(condition, valueIfConditionIsTrue, valueIfConditionIsFalse)
This is how excel interprets the command in a way that's easier for us to understand:
if A1 == "O":
output = 1
else:
if A1 == "V":
output = 2
else:
if A1 == "G":
output = 3
else:
if A1 == "U":
output = 4
else:
output = ""

I think the easiest solution would be to create a look up table and then use a combination of the INDEX MATCH functions to grab the appropriate value. You can read more about INDEX MATCH here: https://exceljet.net/index-and-match
To start, create a table similar to this:
Then assuming you have a list of letters you are trying to match you can write a formula similar to this: =INDEX(Table1[Output],MATCH(E3,Table1[Letter],0)). If you want the formula to return blanks "" instead of #N/A, you can wrap the formula in an IFERROR:
=IFERROR(
INDEX(Table1[Output],MATCH(E3,Table1[Letter],0))
,"")
Here's a picture of the final output.

Related

2D vector lookup [x;y]

I've got a matrix, with two coordinates [i;j]
I'm trying to automatize a lookup:
As an example, this would have the coordinates of [1;2]
Here's a table of all the coordinates:
So here, obviously [1;2] would equate to 143,33
To simplify the issue:
I'll try to go step by step over what I'm trying to do to make the question bit less confusing.
Think of what I'm trying to do as a function, lookup(i, j) => value
Now, refer to the second picture (table)
I find all rows containing index [i] (inside column C) and then
only for those rows find row containing index [j] (inside column D ∩ for rows from previous step)
Return [i;j] value
So if u invoked lookup(2, 4)
Find all rows matching i = 2
Row 5: i = 2 ; j = 3
Row 6: i = 2 ; j = 4
Row 7: i = 2 ; j = 5
Lookup column j for j=4 from found rows
Found row 6: i = 2 ; j = 4.
Return value (offset for yij column = 143,33)
Now this isn't an issue algorhitmically speaking, but I have no idea how to go about doing this with excel formulas.
PS: I know this is reltively simple vba issue but I would prefer formulas
PSS: I removed what I tried to make the question more readable.
You can use SUMPRODUCT, which return 0 for not found values:
=SUMPRODUCT(($C$4:$C$18=$I4)*($D$4:$D$18=J$3)*$E$4:$E$18)
or AGGREGATE, which returns an error that can be hidden by the IFERROR function:
=IFERROR(AGGREGATE(15,6,(1/(($C$4:$C$18=$I12)*($D$4:$D$18=J$3)))*$E$4:$E$18,1),"")
You can use SUMIFS here assuming you will not have exact duplicate combinations of [i, j]. If you did have a duplicate combination, the amounts will be summed and placed in the corresponding cell
In cell B2 place this equation: =SUMIFS($Q$2:$Q$16,$P$2:$P$16,B$1,$O$2:$O$16,$A2) and drag across and over as needed
IF you want to convert the 0's to blanks you can nest the above formula inside a text formatter like so:
=TEXT([formula], "0;-0;;#")

countif excel with value in column A or column B

I want to use COUNTIF in Excel, but I want to count rows where column V = yes OR column U = yes, with all the other criteria the same.
It is easy to use or with values in 1 column, such as P4:P999 = "apple" or "orange", but how to use or over multiple columns?
Below is an Excel code sample written to be readable. The only solution I found was to use addition and rewrite the entire code, but I hate this solution because it is too long.
SUM(COUNTIFS(
P4:P9999, {"apple", "orange"},
B4:B9999, "potato",
AF4:AF9999, "",
V4:V9999, "Yes"
)
) +
SUM(COUNTIFS(
P4:P9999, {"apple", "orange"},
B4:B9999, "potato",
AF4:AF9999, "",
U4:U9999, "Yes"
)
)
Switch to SUMPRODUCT:
=SUMPRODUCT(((P4:P9999 = "apple")+(P4:P9999 = "orange"))*(B4:B999="potato")*(LEN(AF4:AF999)=0)*((V4:V9999="Yes)+(U4:U9999="Yes")>0))

Excel formula using more if

I have a problem with my nested if condition as an Excel formula. I know it would be easier by using VBA, but I have to do it this way.
This is my formula, but it returns FALSE:
=IF(D:D="SUPER";IF(AND(AA:AA="0";AA:AA="1");"V";IF(AA:AA="3";"R";"O")))
The D:D column has 3 filters, I have to apply the same formula with each filter.
The AA:AA column has the following conditions:
- if 0 and 1 -> V
- if 3 -> R
- if anything else -> O
I don't know why it doesn't work, but I would appreciate any advice!
This will return R, because there is 3 in there
enter image description here
I think this is more a matter of prioritizing logic flow. It seems that at least a single occurrence of SUPER with 3 supersedes the rest. The next priority would be SUPER with 0 and SUPER with 1 (both must occur). If none of those apply, default to O.
=if(countifs(d:d, "super", aa:aa, 3), "R", if(not(and(countifs(d:d, "super", aa:aa, 0), countifs(d:d, "super", aa:aa, 1))), "O", "V"))
'with semi-colons
=if(countifs(d:d; "super"; aa:aa; 3); "R"; if(not(and(countifs(d:d; "super"; aa:aa; 0); countifs(d:d; "super"; aa:aa; 1))); "O"; "V"))
=IF(COUNTIFS(D:D;"super";AA:AA;3)<>0;"R";IF(COUNTIFS(D:D;"super";AA:AA;1)*COUNTIFS(D:D;"super";AA:AA;0)=0;"O";"V"))
The order of the criteria was wrong, also you generally can't refer to entire columns in the way you did. This formula first checks whether there's any cell with the value 3. Then if there isn't it multiplies the count of 1s and 0s to check whether there are both numbers present.

keeping a running sum of a formula with conditions

I am having an issue with an excel problem and cannot use vba or add any extra columns. The problem goes along with the format of this image. I could not find anything on google that helped me with this problem and im sorry if it has been asked before.
Example Image
On a separate page in a cell i need to write a function that will check if Info 2 = "z" and Info4 = "x" and if that is true then i need to do the following equation with the numbers in Info1 and Info3: Info1*(1 - Info3)
I will also have to keep a sum of these numbers.
For this example I would want the cell with the formula to equal -34 by doing the following:
3*(1-4)+5*(1-6) = -34
I would want the cell to just display the finished sum
Any help would be greatly appreciated,
Thank you!
You are looking for the mighty powers of SUMPRODUCT
=SUMPRODUCT((B:B="z")*(D:D="x")*(A:A)*(1-C:C))
The first two multipliers will make sure we only evaluate those rows having z for B and x for D. While the latter two are your desired function. Excel will evaluate this for each row and sum up the results.
I am using psuedo values below but this should work:
= [value of cell above] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
so basically starting in the middle, you have a two truth tests,
[info2] = "z", [info4]= "x"
using AND() requires they both pass
and([info2] = "z", [info4]= "x")
if they do pass you want to do your formula:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),FALSE)
but since we want to sum all values for each iterative row we make not passing this test 0:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
Ok so this works for one row, but doesn't sum the numbers from the tests on the previous row:
= [value of cell above or 0 for first row] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
an example written with real excel ranges that you may have to tweak depending on where your values are stored:
Sample picture

Trying to construct an IF statement in Excel with multiple conditions

Basically I need to calculate a column that sum's previous columns only if:
The number in column Q > 4,
Column S = 'N' (its a 'Y' or 'N' flag in this column and I only want to sum if there is an 'N'
P != 0 (There is a number in column P.)
This is the incorrect statement which I came up with:
=IF((Q2>4) AND (S2='N') AND (P2 != 0), V2)
(Column V contains the calculation I want to make, given that these conditions are met.
Kinda lost here guys, would really appreciate any help.
All the best.
EDIT: fixed single-quote>>double and != >> <>
=IF(AND(Q2>4, S2="N", P2<>0), V2, "")

Resources