Excel index row - excel

I have unmatched data with missing rows in excel that i need to match.
Column A contains distinct sample names which match those in Column C. Column C has all of the samples and Column A has only those samples with an observation. Column B has the observations corresponding to Column A. In Column D I need to put the observations in Column B which correspond to the sample in Column C OR 0 (if there was no observation, which is indicating for the sample not being present in Column A).
Example:
A B C D
C2 8 C1 0
C4 10 C2 8
C5 1 C3 0
C9 5 C4 10
C5 1
C6 0
C7 0
C8 0
C9 5
How can I create Column D? Thanks!

You can start with this formula in cell D1 and fill down.
=IFERROR(VLOOKUP(C1,$A$1:$B$4,2,FALSE),0)
The VLOOKUP looks at the value in cell C1 and checks the left column of the table in cells A1:B4 for a match. If one is found, the value in the 2nd column corresponding to the match is returned, if a match is not found, a #N/A error is returned.
That is where the IFERROR formula comes in. If an error is detected in the formula (which means no value was found), then it fills in a 0.

Place the following in cell D1 and drag-down:
=IFERROR(VLOOKUP(C1, $A$1:$B$4, 2, FALSE), 0))

=IFERROR(INDEX($A$1:$C$9,MATCH(C1,$A$1:$A$9,0),2),0)
I'm a fan of the index match match method, instead of vlookups. It allows you to grab basically anything in a defined array, by finding the row and column in the data set and giving you whats in that cell.
The index is your data (A1:C9)
The first match returns the row the data is in ( basically find whats in cell C1 in the A column)
Since we know its in Col 2 of the data I just put 2, but you could use another match to find a column header (customer #, date, part # etc)

Related

Jump to the next non-empty cell and use lates value in the list

I have the following Excel spreadsheet:
A B Desired Result Column B
1 Product A 50 **50** **50**
2 Product B =IF(A2="","",B1) 50 50
3 =IF(A3="","",B2)
4 Prodcut C =IF(A4="","",B3) 50 **40**
5 =IF(A5="","",B4)
6 ="" =IF(A5="","",B5)
7 Product D =IF(A5="","",B6) 50 40
8 Product E =IF(A5="","",B7) 50 40
** Input of User
In Column A there is a list of different products. As you can see there can either be empty cells or cells with formula ="".
In Column B I want to achieve that the last value before the first empty cell or ="" cell applies to the other rows.
For example: If I enter a 50 in Cell B1 I want to achieve that this 50 appears next to every product and empty cells or ="" are ignored.
I can achieve this with the following formula:
=IF(A2="","",$B$1)
Now the problem is, that the user can also type a different number in another cell in Column B. For example he could type in a 40 in Cell B4.
In this case I want that the 40 applies to all other following rows instead of the 50 as you can see in the section "Desired Result Column B" in the example above.
How do I have to change my formula in Column B to achieve this?
Enter the following formula in Cell B2
=IF(A2<>"",INDEX($B$1:$B1,MAX(IF($B$1:$B1<>"",1,0)*ROW($B$1:$B1))),"")
Drag/Copy down as required.
This is an array formula so commit it by pressing Ctrl+Shift+Enter.
Try:
B2: =IF(A2="","",LOOKUP(2,1/LEN($A$1:A1),$B$1:B1))
With the addressing mode used in the LOOKUP formula, it will examine the rows up to the row before the lookup. If the column A value is not blank, lookup_vector will match the last non-blank cell in column A prior to the row containing the formula, and result_vector will return the value in the same row in column B.
It is rather critical that your user entries are restricted as you have described above.
If the user can make an entry in column B that does NOT correspond to an entry in column A, and you want that entry to be copied down, then use:
=IF(A2="","",LOOKUP(2,1/LEN($B$1:B1),$B$1:B1))
Also, note that the sequence will be upset if the user deletes an entry in column B, instead of replacing it with another number. The formulas below the deletion will interpret the deleted value as a zero.

SUMPRODUCT to get row +1

I have a table like below:
12/7/2012 A B
100
12/21/2012 A I
20
12/23/2012 A I
25
12/1/2013 A I
20
12/1/2014 A I
20
I want to get the value in column D where column B is "A" and column C is "I". I used a sumproduct to get the value in column D, but I need to go down 1 row from wherever column B is "A" and column C is "I". This is my formula:
=SUMPRODUCT(--(B:B="A"),--(C:C="I"),F:F+1).
It should return a value of 85, but it returns a value of 4.
You could use
=SUM((B1:B10="A")*(C1:C10="I")*(D2:D11))
as an array formula with CtrlShiftEnter
or
=SUMPRODUCT(--(B1:B10="A"),--(C1:C10="I"),(D2:D11))
and extend the range as far as you need to.
What happens with your formula
=SUMPRODUCT(--(B:B="A"),--(C:C="I"),D:D+1)
is that it is just adding one to each row in column D. D1, D3, D5 and D7 are empty cells so count as zero. So for the four matching rows it is adding one to the total and the result is 4.
If =SUMPRODUCT(--(B:B="A"),--(C:C="I"),D:D+1) worked it may just be coincidence. You might check by taking a copy and in that deleting D1 with Shift cells up then applying:
=SUMIFS(D:D,B:B,"A",C:C,"I")
Or of you don't have SUMIFS filter to delete rows that do not contain a date in ColumnA, A in ColumnB and I in ColumnC, then summing ColumnD.
With SUMIFS an alternative to #Tom's SUMPRODUCT might be:
=SUMIFS(D2:D1000001,B1:B1000000,"A",C1:C1000000,"I")

Count how often a value in a cell in one specific column is not the same as the value in the same row of a specific other column

Both ColumnA and ColumnB are blank except for O and R (individually).
How can I count the number of times a row contains O in ColumnA and R in the same row of ColumnB together with a row that contains R in ColumnA and O in the same row of ColumnB?
For example the result for the example below should be 5 as indicated by the asterisks:
All cells not shown are blank.
The second row is counted because A2 does not equal B2. The first row is not counted because both A1 and B1 contain just O. The fifth row is counted because within a given row it does not matter whether O is in ColumnA and R in ColumnB or R in ColumnA and O in ColumnB. The seventh row is not counted because both A7 and B7 contain just R.
Hopefully:
=COUNTIFS(A:A,"O",B:B,"<>"&"O")+COUNTIFS(A:A,"R",B:B,"<>"&"R")
For equal:
=COUNTIFS(A:A,"O",B:B,"O")+COUNTIFS(A:A,"R",B:B,"R")
If you are just looking for a count of rows where A is not equal to B you can use the following formula:
=SUMPRODUCT((A1:A50<>B1:B50)*1)
Sumproduct will compare each row in A1 through A50 with the values in A and B. If they are not equal it will add 1 to the overall count, counting for each row 1 though 50.
If you would like an indicator in Column C to tell you if A and B is not equal for each row you can just use:
=A1<>B1
Put that in C1 and copy down for each row.

Compare a single row with a column and extract the value from another column on the same row in Excel

So I'm looking for a formula or anything that does something like this:
I have 4 Columns. A B C D.
I have a column (A) with multiple values that can have duplicates.
A1: A
A2: A
A3: B
A4: C
A5: C
I want to compare each row with a Column (B) that has one of each value. So B1 = A, B2 = B etc.
However the value I want to extract to column "D" is in Column "C". So if A1 equals anything in the Column B, I want to extract the value in Column C on the same row, to Column D.
So in D1 I want the value from C1. In D2 I want the value from C1 as well. But in D3 I want the value from C2.
This seems to work:
=VLOOKUP(A1:A5,B1:C5,2,0)
Entered as Array Formula in D1:D5 using Ctrl+Shift+Enter.
Result:

How do I formulate offset function for nth column in different sheet

I've been struggling with this all day, though I'm sure it's not impossible.
I have a sheet with a value in every 3rd column and I need to copy this value into another sheet, ignoring the 1st and 2nd column.
So for: A1, B1, C1, D1, E1, F1 in sheet 1
I just need C1 , F1 in sheet 2
Is there a formula that I can drag across all columns? This has to happen for rows 1 - 150 as well.
This should do it:
=OFFSET(Sheet2!A1,0,COLUMN()*2,1,1)
Modify the sheet name as necessary.
Use the argument Column()*2 for the column offset. This takes the integer value of the current column number, and multiplies it by 2. So the offset for column A is 2, which refers to column C, the offset for column B is 4, which refers to column F, etc.

Resources