VLOOKUP with multiple column matches - excel

Sheet 1
A | B | C
0 | 100001 | 855.71
0 | 100002 | 73.68
0 | 100003 | 704.58
0 | 100004 | 0
0 | 100005 | 0
0 | 100006 | 604.57
0 | 100007 | 15638.66
0 | 100008 | 1085.85
Sheet 2
A | B | C
0 | 100001 |
0 | 100002 |
0 | 100003 |
0 | 100004 |
0 | 100005 |
0 | 100006 |
0 | 100007 |
0 | 100008 |
0 | 100009 |
0 | 100010 |
0 | 100011 |
This is what my 2 sheets in Excel looks like, I need to do a vlookup on the 2nd page that looks up the table in the first sheet, and prints out what is in Column C if column A and B match. So the match 0 and 100001 would display 855.71.
I've tried concatenating colum A and B together and matching that using this formula:
=VLOOKUP(A3&B3,Sheet1!$A$1:$D$8,3,FALSE)
But i just get the #N/A error, any help would be great.

You'll have to concatenate in a new 4th column on Sheet1 to use Vlookup in this manner. Instead though, you could use sumifs() since your lookup is a number and the lookup values appear to be unique:
=sumifs(Sheet1!C:C,Sheet1!A:A,A1,Sheet1!B:B,B1)
As an alternative, if the values in C are not numerical and you don't want them summed, you could use a combination of index() and sumproduct() where sumproduct() will provide the row number on which a match is found and index() will retrieve the value from that row:
=index(Sheet1!C1:C500, sumproduct((A1=Sheet1!A1:A500)*(B1=Sheet1!B1:B500)*Row()), 1)
That's ugly but it will get you out of having to make a superfluous column just for concatenating a key. Note that this will only work if there A and B are unique. If there are more than row where A and B are the same, then the ROW() returned will be summed and the lookup will be incorrect.

Related

How to identify rows of FILTER() when the result is 0?

Dear Excel masters please take a look. I have a nested function like this:
=ROWS(FILTER(Table,Table[Col.A]="d",0))
Here's the table:
| Col.A | Col.B | Col.C |
|-------|-------|-------|
| a | 1 | 6 |
| b | 2 | 7 |
| a | 3 | 8 |
| b | 4 | 9 |
| c | 5 | 0 |
The inner function FILTER returns 0 since there's no "d" in Col.A, but ROWS(0) returns 1 not 0. Is there any solution or replacement that can make it return the correct result 0?
If I wanted to be really pedantic and avoid Iferror (in case it masked a different error) I would use
=LET(filter,FILTER(Table,Table[Col.A]=E3,0),IF(#filter=0,0,ROWS(filter)))
Why is the # necessary? Because otherwise it would check the filtered data cell by cell and you would get this:
where the filtered cells are replaced by rows() except where they contain zero.
If you omit the 0 from the FILTER-Formula, you will receive an error - which you can use to return 0 for the rows count:
=IFERROR(ROWS(FILTER(Table,Table[Col.A]="d")),0)

Count rows in column until sum is reached excluding negatives

I am trying to count the number of rows (in this case days) until the sum of positive values >= the original negative value or more conceptually an initial investment is fully paid-off. In the below example:
For the -70 (1/1/2021) the value would be 8 (1/1/2021 - 1/8/2021) inclusive.
For the next -70 (1/2/2021) the value would be 9 (1/2/2021 - 1/10/2021) inclusive.
For the next -30 (1/6/2021) the value would be 6 (1/2/2021 - 1/11/2021) inclusive.
I have found the following array formula that works for me:
=MATCH(D2,SUBTOTAL(9,OFFSET(B2,,,ROW(B2:B17)-ROW(B2))),1)
However, this does not pass over the other negative values in the column.
Requirement not to use helper columns if possible
Example of what I am trying to achieve:
+-----------+--------+----------------+
| Date | Amount | Desired Result |
+-----------+--------+----------------+
| 1/1/2021 | -70 | 8 |
+-----------+--------+----------------+
| 1/2/2021 | -70 | 9 |
+-----------+--------+----------------+
| 1/3/2021 | 0 | 0 |
+-----------+--------+----------------+
| 1/4/2021 | 0 | 0 |
+-----------+--------+----------------+
| 1/5/2021 | 0 | 0 |
+-----------+--------+----------------+
| 1/6/2021 | -30 | 6 |
+-----------+--------+----------------+
| 1/7/2021 | 40 | 0 |
+-----------+--------+----------------+
| 1/8/2021 | 30 | 0 |
+-----------+--------+----------------+
| 1/9/2021 | 0 | 0 |
+-----------+--------+----------------+
| 1/10/2021 | 70 | 0 |
+-----------+--------+----------------+
| 1/11/2021 | 30 | 0 |
+-----------+--------+----------------+
Any help would be appreciated -
Well I've come up with a formula that agrees with your figures. It may be more complicated than it needs to be because although your test data always works out so that the exact amount is paid off (exact match), I've added the case where an excess amount is paid (inexact match).
The principle is to develop a triangular matrix which uses mmult to select just one row of data, then two rows etc.
=IF(B2<0,IFERROR(MATCH(-SUMIF(B2:B$2,"<0"),MMULT(N(ROW(A$2:A$12)>=TRANSPOSE(ROW(A$2:A$12))),IF(B$2:B$12>0,B$2:B$12,0)),0),
MATCH(-SUMIF(B2:B$2,"<0"),MMULT(N(ROW(A$2:A$12)>=TRANSPOSE(ROW(A$2:A$12))),IF(B$2:B$12>0,B$2:B$12,0)),1)+1)-ROW()+2,0)

Excel lookup upwards

I am trying to lookup data that is the first occurrence of an ID looking upwards in excel. I would like to stop looking upwards when the cell value is ID is 0.
I have used the following to find the first occurrence when looking upwards:
In Cell D8:
=LOOKUP(2,1/($A$2:A8=C8),$B$2:B8)
In Cell D9:
=LOOKUP(2,1/($A$2:A9=C9),$B$2:B9)
For the case of desired outcome = 13 this works, however when there are consecutive IDs I would like to return the top most non-zero data field. Example desired outcome = 15 with the current formula returns 0.
How can I continue looking upwards until the top most ID = 2 before ID =0?
+----+------+--------------+-----------------+
| ID | Data | Lookup Value | Desired Outcome |
+----+------+--------------+-----------------+
| 2 | 18 | 1 | No Formula |
+----+------+--------------+-----------------+
| 1 | 25 | 2 | No Formula |
+----+------+--------------+-----------------+
| 0 | 0 | 0 | 0 |
+----+------+--------------+-----------------+
| 1 | 13 | 0 | 0 |
+----+------+--------------+-----------------+
| 2 | 15 | 0 | 0 |
+----+------+--------------+-----------------+
| 2 | 0 | 0 | 0 |
+----+------+--------------+-----------------+
| 2 | 0 | 1 | 13 |
+----+------+--------------+-----------------+
| 1 | 0 | 2 | 15 |
+----+------+--------------+-----------------+
| 0 | 0 | 0 | 0 |
+----+------+--------------+-----------------+
| 0 | 0 | 0 | 0 |
+----+------+--------------+-----------------+
Put this in D4 and copy down:
=IFERROR(LOOKUP(2,1/(($A$2:A4=C4)*($B$2:B4<>0)),$B$2:B4),0)
Put this in D4 and copy down:
=IFNA(LOOKUP(9^9,1/B$2:B4^-1/($A$2:A4=C4)),)

Excel Data Validation - Add only Dates with 1

I have in Row 4 across my columns a flag which is either 1 or 0.
Row 7 contains my dates across columns.
I am trying to do a dropdown validation for only the dates which have 1 as the flag in their column.
=OFFSET(LEDGER!$M$7,0,COUNTIF(LEDGER!$M$4:$CV$4,"=1"),0)
this doesn't seem to work. Is what I am looking do-able?
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | | |
|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|---|---|
| 31-Dec-10 | 31-Dec-11 | 31-Dec-12 | 31-Dec-13 | 31-Dec-14 | 31-Dec-15 | 31-Dec-16 | 31-Dec-17 | | |
If your dates starts from D7 and if the flags starts from D4 then try this formula.
=OFFSET($D$7,0,0,,COUNTIF($D$4:$K$4,"<>0"))

Count row that have value in two separate columns

So i'm trying to count who sold something at the end of the day doesn't matter how many item that person sold.
Name Shoes Shirts Hat
A 1 2
B 1
C 1 3
D 1 1
E
So if A sold then should count as 1 person sold something
If E is not selling anything that not count as anything
Example spreadsheet with data from C6 through F10:
| C | D | E | F |
5 |name|shoe|shirt|hat|
6 | a | 1 | 1 | 0 |
7 | b | 0 | 1 | 0 |
8 | c | 1 | 1 | 0 |
9 | d | 1 | 1 | 0 |
10| e | 0 | 0 | 0 |
You could use this formula on the data example above:
=SUM(IF($D$6:$D$10+$E$6:$E$10+$F$6:$F$10>0,1,0))
but you have to hit Ctrl+Shift+Enter, not just Enter (because it is an array formula). You will know you did this correctly because it automatically adds { } around the formula, so it will look like this:
{=SUM(IF($D$6:$D$10+$E$6:$E$10+$F$6:$F$10>0,1,0))}
What this formula does:
IF(D6+E6+F6 > 0, 1,0) for each row until 10+E10+F10, which leaves you with either a 1 or 0 for each row; 1 if the sum of the row > 0 and 0 if it was not > 0. It then adds up the info and gives you a count of any rows that had at least 1 sale of either a shoe, shirt or hat.

Resources