If-then statement with multiple options - excel

I have been working on an IF statement where there are multiple answers but I can't seem to get the formula to work. The If statement is going to look at two columns of data and should pull back the first NUMBER. Sometimes the first column will say "#N/A N/A" in which case the formula should look to the second column and pull that NUMBER. If both columns say "#N/A N/A" then I would like the answer to be "NR".
In another scenario I will have three columns of data. I would like the formula to pick up the first number in the columns no matter what follows. Again, if all three columns say "#N/A N/A" I would like the answer to be "NR".
I will attach two examples of what I am talking about. Here is the formula I have now but I can't seem to get it to work:
=IF(ISBLANK(B3),"",IF(D3="#N/A N/A",$D3,$D4))
Unfortunately, this formula isn't taking into account if D3 is actually a number. It also doesn't account for if both D3 and D4 are "#N/A N/A".
Any help would be greatly appreciated.
Thanks,
Here is the example :

This allows the use of many columns without the need for multiple nested ifs.
It will return the first column that is not #N/A N/A:
=IFERROR(INDEX(3:3,,AGGREGATE(15,6,COLUMN(D3:E3)/(D3:E3<>"#N/A N/A"),1)),"NR")
So to do more columns simple change both the D3:E3 to the range desired. The 3:3 should match the row being searched.

You can check each cell (from left to right) and return the first instance of a numerical value using a combination of IF & ISNUMBER
Checking 2 Columns
=IF(ISNUMBER(D3),D3,IF(ISNUMBER(E3),E3,"NR"))
Checking 3 Columns
=IF(ISNUMBER(D3),D3,IF(ISNUMBER(E3),E3,IF(ISNUMBER(F3),F3,"NR")))

Related

Find a value in a range (any of multiple column or rows) and return the value in far left most column of that row

Looking for something like a typical index match formula that can look to the right and return value to the left, but look at all columns in a range. Take below valid formula for example.
(Excel 2021.)
Finds A1's value in column D, and it returns value from column C.
=INDEX($C$1:$C$10,MATCH(A1,$D$1:$D$10,0))
In my ideal world I can Keep $D$1 and change $D$10 to $F$10 so it searches all columns D/E/F, and still returns C like below. However that does not work in our real world, any other ideas please? Thanks!
=INDEX($C$1:$C$10,MATCH(A1,$D$1:$F$10,0))
Update*
To clarify there are mix of letters and numbers. Also this table will be about 50k rows so hoping as simple as possible.
Also Column C will all be unique for sure, and D-F should be unique values but there is a chance a mistake and a few duplicates might be in.
You need MMUL() with INDEX(). Try below formula if you have Excel-365.
=FILTER(C1:C10,MMULT(--(D1:F10=A1),SEQUENCE(COLUMNS(D1:F1))))
For older version try
=INDEX($C$1:$C$10,LARGE(MMULT(--($D$1:$F$10=A1),TRANSPOSE({1,1,1}))*ROW($C$1:$C$10),1))
Since your INDEX/MATCH take from the same rows, you can first simplify your original search with
=XLOOKUP(A1,$D$1:$D$10,$C$1:$C$10)
XLOOKUP combines HLOOKUP and VLOOKUP with exact match being the default.
This will work for searching three rows
IFERROR(IFERROR(XLOOKUP(A1,$D$1:$D$10,$C$1:$C$10), XLOOKUP(A1,$E$1:$E$10,$C$1:$C$10)), XLOOKUP(A1,$F$1:$F$10,$C$1:$C$10))
We can name the columns colC, colD, colE, and colF and it becomes
IFERROR(IFERROR(XLOOKUP(A1,colD,colC), XLOOKUP(A1,colE,colC)), XLOOKUP(A1,colF,colC))
As with other lookups, this returns the first value or #N/A error.
This could be made more scalable for higher number of rows if we are allowed to add a column somewhere.

Excel VLOOKUP/ INDEX multiple times based on value

So I want to be able to change the values from Pic2 in rows "ZERO" and "LINE-IN" and have it reference the table to output the value from the even number of rows. In Pic2 if I enter "AA","CC","BB" into row "ZERO" and "3","2","1" into row "LINE-IN" then it would take "AA" from "ZERO" on Pic2 go to column A on Pic1 and find the match, then Look within row 1 Pic1 to find "3", then output "Z" from row 2 into the "LINE-OUT" row. So, the value "CC" in row "ZERO" with value of "2" in row "LINE-IN" will output the value of "X".
I have came across a few possible ways to accomplish this using VLOOKUP, INDEX, MATCH, and IF. All solutions and the ways I can think to do what I asking requires to build multiple tables and that doesn't seem very practical the way I am imagining.
I am really looking for one or two formulas that I can reference instead of making several different tables to accomplish the same thing.
Thanks for any help or guidance towards a solution and sorry about having to follow the links for the pics.
I'm confused about how you've set your table up. If you set it up as follows:
then it is a very simple Index/Match function.
For instance, if the tables were arranged as above, then the formula in cell B8 that will change as you change cells B6 and B7 is:
=INDEX($A$1:$D$4,MATCH(B7,$A$1:$A$4,0),MATCH(B6,$A$1:$D$1,0))
and you only need one table

Excel: Get values in non-adjacent cells based on multiple criteria

I have an excel sheet sort of like this:
I'm trying to figure out how to get the totals in cells B1 through B4.
I tried INDEX-MATCH, where I tried to match the words in A1:A4 with the words in row 7, get the numbers relative to them, and then sum them, but it was a lot of Google searching and stabbing in the dark -- every attempt returned an error.
I also tried to INDEX-MATCH the words in A1:A4 with row 7, and then nest a VLOOKUP in there where it'd get the number relative to "visits:" but that didn't work at all either.
Is INDEX-MATCH even the correct function? Any help would be much appreciated, I'm not even sure what to Google anymore.
EDIT: I need to use a search function of some kind, like the INDEX-MATCH method, rather that static formulas because the sheet will change periodically and I don't want to have to update the formula every time I add an animal.
Your data table is unusual in structure.
However, if you are gong to keep a fixed rule such that the number of visits is always offset 2 rows and 1 column from the animal type(and that itself is always in row 7), you could do:
In B1:
=SUM(IF($A$7:$AAA$7=$A1, $B$9:$AAB$9, 0))
Confirm with Ctrl-Shift-Enter, and then copy down..
DOes this work?
=SUM(IF($B$7=A1,$C$9,0),IF($D$7=A1,$E$9,0),IF($F$7=A1,$G$9,0),IF($H$7=A1,$I$9,0))
I'm not sureto have fully grasped your challenge. Yet it seems the following solution would work:
Add the following formula in each box where the number of visits is added as
=+SUMIF($A$1:$A$end;animal;$B$1:$B$end)
Where end is a number of the last cell in the first and second columns data contain the data.
And animal is the cell that contains the name of the animal.
Therefore in your simple example, the formulas on cells C9;E9;G9 and I9 would be respectively:
=+SUMIF($A$1:$A$4;B7;$B$1:$B$4) ; =+SUMIF($A$1:$A$4;D7;$B$1:$B$4); =+SUMIF($A$1:$A$4;F7;$B$1:$B$4) and =+SUMIF($A$1:$A$4;H7;$B$1:$B$4).

Returning a value if three columns match in excel

I have two excel sheets where I need to match three values to return a fourth. The similar columns are month, agent, and subdomain. The fourth column is called difference.
Concatenate would work, as per #MakeCents suggestion, but if you don't want a helper column, SUMPRODUCT would work.
example:
=SUMPRODUCT(--(A2:A12="d"),--(B2:B12="S"),--(C2:C12="Apr"),D2:D12)
would search range A2:A12 for "d", B2:B12 for "S" and C2:C12 for "Apr", and return the value fom D2:D12 that corresponds to where all 3 are true. If multiple lines match, it will add the value in D2:D12 for all matching rows.
The -- is used to change the True/False results into 0 and 1 for use in multiplication
Limitations of SUMPRODUCT
Recommended to specify the range explicitly; it will be slower with just
column references
(A1:A4000 is ok, A:A is not)
It will return an error if any of the values are errors
It will return numeric results only - text is evaluated as Zero
Although I believe #MakeCents comment / suggestion on how to do this is the way I would go since it is the simplest, you could accomplish this a different way (MUCH more processor-intensive, though) using the Index() and Match() functions and Array formulas.
For example, suppose your 3 columns of data you're looking to match against are columns A-C and you're looking to return the matching value from column D in Sheet1
Now, the 3 values you're looking to have matched are in cells A1, B1 & C1 of Sheet2, you could use the following formula:
=INDEX(Sheet1!D:D,MATCH(1,(Sheet1!A:A=A1)*(Sheet1!B:B=B1)*(Sheet1!C:C=C1),0))
And ENTER IT AS AN ARRAY FORMULA by pressing Ctrl + Shift + Enter
Hope this helps!
You are looking for a Lookup with multiple criteria.
One of the most robust options is
=INDEX(D:D,SUMPRODUCT(--(A:A="d"),--(B:B="S"),--(C:C="Apr"),ROW(D:D)),0)
It does not need to be entered as an array formula.
Taken from [1] (blogs.office.com).
See also this very complete answer, which summarizes this and other options for performing a lookup with multiple criteria.
PS1: Note that I used references to full columns, as per this.
PS2: This can be considered an enhancement to the solution by Sean for the case when the output column does not contain numbers.
References
[1] This post is written by JP Pinto, the winner of the Great White Shark Award given for the best article written about VLOOKUP during VLOOKUP Week.
Try this
=IF(A4=Data!$A$4:$A$741,IF(B4=Data!$B$4:$B$741,"Hai"))

Compare 2 lists in Excel ?

I have 2 columns in a spreadsheet. One column has around 26 extra rows than the other. I've been trying various formulas to highlight or somehow indicate which columns are missing from the smaller of the lists...
I tried filling a 3rd colum with this :
=FIND(B1,A1:A1102)
which I though returned 1 if b1 was in the list a1:a1102 alas it doesn't seem to be true.
Anybody got any solutions for comparing 2 lists and isolating differences?
Thanks
To use MATCH, go with something like the following:
=IFERROR(MATCH(B1,$A$1:$A$1102,0),0)
entered into cell C1 and copied down to the end of the data in column B
This assumes that column B contains the longer list and A the shorter, of course.
The MATCH formula will return the row in which B1 is matched in A.
You can use a combination of if, iferror and vlookup functions.
=IF(IFERROR(VLOOKUP(B1,$A$1:$A$10,1,FALSE),"missing")="missing", 1, 0)
This will find matches in column A for the values in column B. If the value is missing, the iferror will report it missing (#N/A). Then the if function will output a 1 for the missing values and a 0 for those found.
EDITED:
My bad, I suggested the wrong function - except the absolute reference, you need to use MATCH - as suggested in other answers: =MATCH(B1,$A$1:$A$1102,0) or look up the whole column: =MATCH(B1,A:A,0).
Missing items will be returned as #N/A, but it easily handled with IFERROR.
I know this is a bit old, but I could not get MATCH() to work across different tabs in the same workbook. Also, I'd rather not add columns if I don't have to. What worked for me, was to use conditional formatting:
Select one column that you want to test (assume it's 'Z' for this example)
Select Conditional Formatting -> New Rule
Select 'Use a formula ...'
Use =COUNTIF('otherTab'!$A:$A, $Z1) - where 'otherTab' is the name of the other tab, 'A' is the column in that tab you want to test against and 'Z' is the column in THIS tab
Set the color scheme that something that says "I found a match!" to you
Click OK
Then you can do the same on the other column if you need to check both.
I think you need to use MATCH instead of FIND
Or if you want to be fancier about it, check out this thread:
https://superuser.com/questions/289650/how-to-compare-two-columns-and-find-differences-in-excel

Resources