Excel formula for if when there are 3 alternatives - excel

I am trying to get a formula that will work for the following:
if Cell A contains X, then Cell B = Cell C +1, but if Cell A contains Y, then Cell B = Cell C +2, but if Cell A contains Z then Cell B = Cell C +3
any help greatly appreciated

You may be able to use SWITCH :
https://support.office.com/en-us/article/SWITCH-function-47ab33c0-28ce-4530-8a45-d532ec4aa25e

A simple IF statement can be written as below...
=IF(A2="X",C2+1,IF(A2="Y",C2+2,IF(A2="Z",C2+3,"")))
There are various other approaches to get the desired output. One of them is like below...
=IFERROR(CHOOSE(MATCH(A2,{"X","Y","Z"},0),C2+1,C2+2,C2+3),"")

Consider:
=LOOKUP(A1,{"X","Y","Z"},{1,2,3})+C1
EDIT#1:
To use LOOKUP(), the input vector must be in alphabetic order.

Related

OFFSET Formula Modification

I know how the offset formula (e.g. =OFFSET($B$5,(ROW(A1)*n)-1,0)) works. However, can you advise how to modify it to get 1st cell from column B (and then as I drag it down) first cell from C and then second cell from B and second cell from C, and so on?
Thanks
You can try using a mix of OFFSET, MOD and ROUNDUP functions to get an ever-changing mix of rows & cols parameters:
=OFFSET($B$1,ROUNDUP(ABS(ROW(A1)/2),0)-1,MOD(ROW(A2),2))
I included some random values in cells B1:C6 to present the result in a clearer way:

Add many IFs to a formula

Is there an easier and more compact way to write this formula?
[1] [2]
A 0
B 5940
C 13860
D 22500
E 87300
F 378000
=IF(Q27="A",0,IF(Q27="B",5940,IF(Q27="C",13860,IF(Q27="D",22500,IF(Q27="E",87300,IF(Q27="F",378000,"ERROR"))))))
So what it does is return the respective values in [2] if Q27 equals one of the letters in [1].
I managed to get the result I expected but I'd like to know if the code can be improved.
Thanks
That is what VLOOKUP is for. Put your table in A1:B6 then:
=VLOOKUP(Q27,A:B,2,FALSE)
Or you can "Hard Code" the VLOOKUP like this:
=VLOOKUP(Q27,{"A",0;"B",5940;"C",13860;"D",22500;"E",87300;"F",378000},2,FALSE)
Or:
=INDEX({0,5940,13860,22500,87300,378000},MATCH(Q27,{"A","B","C","D","E","F"},0))
If you have to hard-code the values then maybe,
=iferror(choose(code(upper(q27))-64, 0, 5940, 13860, 22500, 87300, 378000), "error")
The following formula:
=INDEX($B$2:$B$7,MATCH(E2,$A$2:$A$7))
Enter the value you're using to look up in cell E2. If you were to put the formula in cell Q27 as you specified, then you would get the return value in that cell. If you were to put D into cell E2, and have the formula in cell Q27, you would get 22500 in Q27.
Alternatively, if the helper cell E2 isn't an option, you could simply replace E2 in the formula with "A", or "B", or whichever specific value you're using to lookup. Be sure to include quotation marks around it. For example:
=INDEX($B$2:$B$7,MATCH("A",$A$2:$A$7))

How to use multiple columns for texts in Excel

I have multiple columns as follows
A B C D Outcome
Y Y
N N
N N
Y Y
My outcome is in the column E. If the cell is filled, I want to see it in the outcome column. If not I want to see a blank cell. I tried my best, but I could do it. Is there a simple function to do it. Thanks for your help.
There are a number of ways to accomplish this. One would be:
// Copy this down
In Cell E2: =IF(COUNTA(A2:D2)=0,"",CONCATENATE(A2,B2,C2,D2))
Try :
=A2&B2&C2&D2

Copy cells if conditions met - excel

With Excel I would like to copy all cells values if conditions met.
In a specific case, I would like copy all the values from column C to a new column G, but only if the year = 1980 and Cracked password = 1.
Thus, as shown in the example below:
Thanks for the help.
Greetings T.
You can run an if function along column G and then use CTRL + g to delete the blanks
Vinnie's Idea is easier
If you want a formula, put this in G2 and copy down:
=IFERROR(INDEX(C:C,AGGREGATE(15,6,ROW($B$2:$B$12)/(($B$2:$B$12=1980)*($D$2:$D$12=1)),ROW(1:1))),"")
you can use this formula
=IF(AND(A2=1980,C2=1),B2,"")

Excel INDEX and MATCH Get Value

I have an excel workbook that I need some help with INDEX and MATCH or any other Formula that can get me my end result.
Here is sheet1:
SIT_ID METER SUSE_CD
10834282 DT0061 B
10834282 AW7931 P
21676286 CQ9635 P
21676286 DP4838 B
21726281 AW7880 P
21726281 DT0032 B
Here is Sheet2:
Site ID B P
10834282
21676286
21726281
Ultimately what I am trying to do is on Sheet2 is put the Meter that = B for the SITEID in the column and then Put the Meter that = P in the Same row.
I have never used Index or Match and I looked it up online but I am confused and hoping someone can help me with the correct formula or point me in the right direction.
Thanks so much!
INDEX first takes a range, then a row number, an optional column number (and an optional area number).
MATCH takes a value to lookup, an array and a mode.
In your problem you can use the following in Sheet2 cell B2:
=INDEX(Sheet1!$B$2:$B$7, MATCH($A2, IF(Sheet1!$C$2:$C$7=B$1,Sheet1!$A$2:$A$7), 0))
This formula is an array formula and will work with Ctrl+Shift+Enter and then you can fill it to the other cells.
I had to use an IF because there're two conditions to check.
EDIT: Use this one if your cell formats are different:
=INDEX(Sheet1!$B$2:$B$7,MATCH($A2*1,IF(Sheet1!$C$2:$C$7=B$1,Sheet1!$A$2:$A$7*1),0))
EDIT2: Adding trimming:
=INDEX(Sheet1!$B$2:$B$7,MATCH($A2*1,IF(TRIM(Sheet1!$C$2:$C$7)=TRIM(B$1),Sheet1!$A$2:$A$7*1),0))
EDIT3: If you're using it on your full data, change the range:
=INDEX(Sheet1!$B:$B,MATCH($A2*1,IF(TRIM(Sheet1!$C:$C)=TRIM(B$1),Sheet1!$A:$A*1),0))
Assuming your Sheet1 looks like this:
And your Sheet2 looks like this:
The formula in Sheet2 cell B2 and copied over and down to cell C4 is:
=INDEX(Sheet1!$B$2:$B$7,MATCH(1,INDEX((Sheet1!$A$2:$A$7=$A2)*(Sheet1!$C$2:$C$7=B$1),),0))
Note that this is a regular formula, so no need for Ctrl+Shift+Enter
A helper column D is added to initial columns.
D2: =$A2 & $C2
Now it's possible to make a simple search of the concatenated SITE_ID and SUSE_CD:
H2: =MATCH($G2&" B";$D$2:$D$8;0)
The result would be a row number (=1 in this case) for the needed string in array $D$2:$D$8.
INDEX shows the value of the cell, found by counting n-th row (defined by MATCH) and m-th column (=2) in array $A2:$A$8 from the upper left cell (A2).
Altogether: =INDEX($A$2:$B$8;MATCH($G2&" B";$D$2:$D$8;0);2)
The easiest way to get around with this is,
to use concatenation operator in the match function.
Don't forget to use Ctrl+Shift+Enter
Use below formula in column B of Sheet 2
{=INDEX(Sheet1!$B:$B,MATCH(Sheet2!$A2&Sheet2!$B$1,Sheet1!$A:$A&Sheet1!$C:$C,0))}
And the below formula in column C of Sheet 2
{=INDEX(Sheet1!$B:$B,MATCH(Sheet2!$A2&Sheet2!$C$1,Sheet1!$A:$A&Sheet1!$C:$C,0))}
And then flash fill the remaining rows.

Resources