Subtracting columns in a Vlookup - excel

I have a Excel spreadsheet that has two tabs, I have data on the DATA tab and the results of the data on the RESULTS tab. On the RESULTS tab I need to create a vlookup that will look for data on the DATA tab and subtract Column A from Column B. Is this possible with vlookup?
I have a before and after with the same clientID but data being copied/pasted will change.
Before
A B C
1021 102 125.00
1022 102 150.00
1023 105 100.00
After
A B C
1021 102 125.00
1022 102
1023 105 100.00
So each day I take the AFTER number and paste them over the before number, and get my new AFTER numbers from another tab.But if the pasted AFTER number does not have data for that specific account (in this case 1022), and the new AFTER number I get from another tab does not have data for 1022, my comparision will be off an account and will not notify me that this account is missing. I'm sorry, i know that is probably confusing.

I don't actually get why you need to use VLOOKUP to substract two columns...
In the results tab, you could just type
=IF(AND(DATA!B1<>"",DATA!A1<>""),DATA!B1-DATA!A1,"")
And copy the formula down the whole column.
The IF condition checks if both DATA!B1 and DATA!A1 are not empty, in which case it means they both have data and it will substract it. If one of the two columns is empty, it won't do anything, which is what you want.
If I didn't understand your question correctly, feel free to comment and clarify and I will propose something else.
Edit for VLOOKUP solution: I'm assuming that the client IDs are in column A in both tabs and you have to substract B from C in the same row as the ID in the DATA tab.
In RESULTS, use the following formula (put this one in row number 1 and copy it down):
=VLOOKUP(A1,DATA!A:C,3,FALSE)-VLOOKUP(A1,DATA!A:C,2,FALSE)
This will return 0 if both fields are empty, C if only B is empty and -B if only C is empty.
I can modify this if you need a different behavior depending on which columns are empty.
Hope this helps!

Yes it is possible with Vloopup.
=VLOOKUP(ResultsRefID,DATAarray,col1,FALSE)-VLOOKUP(ResultsRefID,DATAarray,col2,FALSE)
you could use that formula where ResultsRefID is the unique row identifier you are trying to get data for, DATAarray is all of the data in the DATA worksheet, and col1/col2 are the columns of data you want to have subtracted.
You can get the same results a little easier (I think) with an IF statement as an array.
=IF(ResultsRefID=DATAarrayUniqueIDrow1:DATAarrayUniqueIDrow1lastRow,col1FirstRow:col1LastRow-col2Firstrow:col2LastRow,"match not found.")
The IF statement has to be entered as an array (ctrl+shift+return)

Related

Excel, Match lookup array to ignore hidden rows

NOTE: I'm using Excel 2016, don't have access to the good stuff in 365 :(
I'm trying to build a summary sheet at the moment. The idea is to filter a table, then have the summary formulas pick out the top 5 values in a given column.
To do this I'm trying to use the Large function in Aggregate which will help me ignore hidden rows while also allowing me to extract the nth largest value.
From there I had thought to use match to find the row number of that value within the column so that I could also get text based values from the same row by assigning a column letter via Indirect.
^This is the crux of what I'm trying to do^
The code looks like this at the moment... (Sales is column "R")
=MATCH(AGGREGATE(14,5,Table1[Sales],1),Table1[Sales],0)+62
Would then go be
=INDIRECT("N"&MATCH(AGGREGATE(14,5,Table1[Sales],1),Table1[Sales],0)+62)
Aggregate(14 = Large*
Aggregate(,5 = Ignore hidden rows*
The 62 there at the end is there as the data in the table starts on row 63 (making it more robust with row() is on my list but not there yet).
The issue I'm having is it seems the lookup array in the Match function Table1[Sales] isn't being filtered as the table is being filtered.
At least that's what the results I'm seeing are indicating to me as the row number I'm getting back isn't within the filtered table (I.e. Match is returning a hidden row number).
My question is if anyone has an idea about how make this so that only visible rows are considered within the array.
(If I've completely missed the mark with this and someone has a better idea about how to accomplish this goal (without having to resort to array functions) I'd be very grateful).
Thanks!
Expected results
row
A
B
1
Company A
425
2
Company B
1500
4
Company A
1200
7
Company C
750
15
Company B
100
19
Company A
100
I'd be looking for the nth largest value in column B, say 1200 (second largest) in this example.
=MATCH(AGGREGATE(14,5,B:B,2),B:B,0)
=MATCH((1200),C:C,0))
=3
The expected result is Row 4, but because (again, it seems) the look-up array isn't excluding filtered/hidden rows, it is returning Row 3 instead.
I hope this is a bit clearer!

Excel Formula to count unique values based on three different criteria

I am trying to get a row by row count of unique invoices in a spreadsheet. I want excel to do this by reading either 1 for unique or zero for duplicate.
I have had success with =IF(COUNTIF($C$3:C3,C3)>1,0,1).
This has given me an accurate count based on one specific column, but I have not had any luck advancing this beyond the one column. I would like this formula to be based on three criteria, not just two.
A B C D E F G
Vendor ID Name 1 Invoice Number Inv Date Sum Amount Acctg Date Unique#
00001 A 0000001 3/16/2015 5.00 5/11/2016 1
00010 M 0000001 9/14/2015 10.00 5/24/2016 1
00010 M 0000001 9/4/2015 15.00 5/24/2016 0
00005 K 0000285 4/8/2016 20.00 4/18/2016 1
000106 O 000042 6/7/2016 30.00 6/21/2016 1
000107 H 006333 4/5/2016 6.00 4/11/2016 1
000107 H 006333 4/5/2016 6.00 4/12/2016 1​
There are duplicates in all the columns because of how I needed to pull the report. I would like a pull down formula that would give me unique values of A, C, F in a 1,0 format on each row line by comparing each of them against a total combination of each of three columns. Please note vendor M having a duplicate invoice number vs vendor H which has two distinct invoices based on the criteria.
This will be a large drain on resources because of the size of the data. I am looking at around 20-90k lines, but maybe someone can show me a better mousetrap? VBA macro? Match Index? Anyway, onwards to the failures!
Please feel free to explain why they didn't work, or how they could. Also please ignore column locations compared to my example as I was moving things around quite frequently.
=A&C&F then use If(countif('ColumnX')), but this didn't work correctly as I found data that was listed as a repeat when it was actually unique. I think the root problem with doing this was combining the date and general formats into one cell.
=SUMPRODUCT((1/COUNTIFS(E3:E1000,E3:E1000,J3:J1000,J3:J1000,G3:G1000,G3:G1000)))
Multiple versions of AND with IF(CountIF)
Multiple versions of =A&C AND CountIF (Date)
I have also looked at the following questions in SE and found them helpful, but ultimately not what I specifically needed, or I failed at implementation.
Simple Pivot Table to Count Unique Values
I tried this unsuccessfully based on unique invoices, need three criteria not just one.
Count unique values in Excel
See above.
Excel Formula: Count Unique Values in a Row Based on Corresponding Value in Another Row
This looks like it should work, but I tried and failed to correctly adapt to my problem.
Excel - Return Count of Unique Values Based on Two Columns
This also should work perfectly with addition of third column. Formula yelled at me and called me names. Mentioned something about can't fix stupid.
Please let me know if any parts of the question are unclear. I did my best to not duplicate and trim the information down. Thanks in advance!
If I am understanding your problem correctly, basically you want column G to check if the current row is a duplicate (based on columns A, C and F) of any rows above it. If it is, return a 0, else return a 1.
If that is what you are looking to achieve, you can do so using the COUNTIFS() function to know if there are any duplicates above the row and then simply check if the count = 0 or is > 0 (=0 means it's unique, >0 means it is a duplicate).
Your formula for column G would look as follows:
G2: 1 (obviously we know it is unique since there are no values above it to be a duplicate of)
G3: =IF(COUNTIFS($A$2:A2,A3,$C$2:C2,C3,$F$2:F2,F3)=0,1,0)
then, drag G3 downwards.
Hope this is what you were looking for.

Need to find a value that matches two columns of criteria. Possible VLOOKUP

Update Below -- 6/4
I have two worksheets in excel. One is a list of donors with their check#/amount/ Donor ID ( "donations" worksheet) and the other is a copy of the accounting info with Donor ID/check#/amounts (quickbooks worksheet). Quickbooks does not have the DonorID's filled in yet.
The issue I have is that i need match up Donor ID's with their checks. To get this i need to match the check# and amount in "Quickbooks" to the same in "Donations", when they match, it will give me the Donor ID that corresponds with that check.
Here is how it is laid out:
Donations Worksheet:
A B C
DonationID Check# Amount
1 179 106 $200
2 210 106 $500
3 220 106 $600
Quickbooks Worksheet:
A B C
DonationID Check# Amount
1 n/a 106 200
2 N/a 1074 500
3 N/a 300 1000
When I ask to find "check# 106 is for $200" it should tell me that it is from Donor 179.
Some checks don't match and are not from donors. The list has close to 50000 names.
Please ask me any questions so i can clarify this more. I am also somewhat new to all this and apologize if I am not to clear.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks everyone for your help. We are not there yet but you were all steering me in the right direction.
I have added a screen shot of the page for reference because the team was having issues making the given formula's work. I also combined the two sheets onto one page so there is less cross worksheet referencing and will be easier to read.
Cknum = Check#
Two column matches typically come in one of two typical configurations; one being an array formula and the other being a standard formula. Both use variations of an INDEX/MATCH function pair.
        
The standard formula for Quickbooks!A2 would be,
=IFERROR(INDEX(Donations!A$1:A$999, MIN(INDEX(ROW($1:$999)+((Donations!B$1:B$999<>B2)+(Donations!C$1:C$999<>C2))*1E+99, , ))), "No match")
The array formula version for Quickbooks!A2 would be,
=IFERROR(INDEX(Donations!A$1:A$999, MATCH(1, (Donations!B$1:B$999=B2)*(Donations!C$1:C$999=C2), 0)), "no match")
Array formulas need to be finalized with Ctrl+Shift+Enter↵ rather than simply Enter↵.
Once one of the formulas has been put in Quickbooks!A2 correctly, fill down as necessary to catch the values from other rows. Note that I have changed the third line of your sample data to demonstrate a second DonationID lookup for Check# 106.
With ~50K records, there is the distinct possibility that multiple matches could be made on both columns B and C. To capture the subsequent second, third, etc matches from the Donations worksheet, change the MIN function to a SMALL function and use a progressive COUNTIFS function to adjust the k ordinal.
=IFERROR(INDEX(Donations!A$1:A$50000, SMALL(INDEX(ROW($1:$50000)+((Donations!B$1:B$50000<>B2)+(Donations!C$1:C$50000<>C2))*1E+99, , ), COUNTIFS(B$2:B2, B2, C$2:C2, C2))), "No match")
After setting up some intentional duplicates in the Donations worksheet like this,
DonationID Check# Amount
179 106 $200
210 106 $500
220 106 $600
979 106 $200
910 106 $500
920 106 $600
You should receive results like the following.
        
The IFERROR function has been used to catch non-matches and show no match rather than the #N/A error.
I have modified the values in your single worksheet sample data to show a variety of matches as well as one case where the chknum and amount were duplicated by two different donationID entries.
    
The matching records are color-coded for quick reference. I've made this sample workbook publically available at my Docs.com-Preview site.
 VLOOKUP_w_Multiple_Criteria_and_Duplicates.xlsx
There is an existing command, DGET, that can be used for multiple criteria.
In your QB worksheet, I added another few rows, starting at A7.
ID CheckNo Amount
106 200
The ID is 179
Note that I changed Check# to CheckNo. I also added a definition of donationDB, from A1 to D4.
The DGet statement is where the 179 is. I used =DGET(donationDB,Donations!B1,Quickbooks!A7:C8)
What the DGET does is to look up the database, tell it you're looking for the Donor ID in B1, using the criteria in the fields A7 to C8.
One quick way out of this problem is to create a Pivot Table on the Donations data and then use GETPIVOTDATA to pull values out of it to get the donation id on the Quickbooks table.
This is easily done if the donation ID is always numeric. You set up a Pivot Table with row fields including check number and amount. You then set the values to be equal to MIN or MAX of the donation ID. If there is only one result you will get it immediately. If there is a clash, you can determine this by switching over to COUNT and flag any of those >1.
Once you have the table set up with MAX you can then quickly use GETPIVOTDATA to pull in the matching value.
This assumes that your amount values are close enough (in the floating point decimal sense) to match. Nearly all will be. Some may not. If you can get 50k records down to 100 though to double check, then life is good.
Picture of sample data and Pivot set up, shows the Pivot Table built on the left data (with the donation ID). The lookup data is on the right.
Formula for the lookup is a simple GETPIVOTDATA, this is in cell F3 and copied down.
=GETPIVOTDATA("Donation",$B$10,"Check",G3,"Amount",H3)
You will get the #REF! error if a match is not made. See the last row for an example.
To compare two sets of data by matching several fields and obtain another field as a result of the match, I suggest to add a new field to each database to create a concatenated value of the Fields to match, then use a VLOOKUP and COUNTIF formulas combined.
Let’s use the sample data provided by Jeeped, in which we have:
Data A: Quickbooks - range D1:M24 and Data B: Donations – range R1:W23, to be extended to C1:M24 and Q1:W23 respectively
Add Field “Key” to concatenate the Fields to match (2 fields in this case, but also works for more), use | as separator.
Data A: Add Field “Key” in Column C and enter this formula
=CONCATENATE($E2,"|",$M2)
Data B: Add Field “Key” in Column Q and enter this formula
=CONCATENATE($V2,"|",$W2)
Enter formulas to match concatenated fields and retrieve required information (also indicates items duplicated)
Data A: Add this formula in column N
=IF(COUNTIF($Q$1:$Q$23,$C2)>1,
"Duplicated: "&COUNTIF($Q$1:$Q$23,$C2),
IFERROR(VLOOKUP($C2,$Q$1:$W$23,2,0),""))
Data B: Add this formula in column X
=IF(COUNTIF($C$1:$M$24,$Q5)>1,
"Duplicated: "&COUNTIF($C$1:$M$24,$Q5),
IFERROR(VLOOKUP($Q5,$C$1:$M$24,2,0),""))
I use the AVERAGEIFS function for getting a numeric value based on multiple criteria. If you are not confident that the criteria would only return one value, then you can wrap in a COUNTIFS statement.
=IF(COUNTIFS($A$1:$A$10, crit1, $B$1:$B$10, crit2) = 1, AVERAGEIFS($C$1:C$10, $A$1:$A$10, crit1, $B$1:$B$10, crit2), #N/A)
This only works for numeric values though.

Return Value in a column based on value in a subset in another column

I'm working on taking information from a table like so:
A 1
2
B 3
1
4
C 2
5
Essentially, a series of sets (A,B,C) with their elements arranged vertically beside them.
What I'm trying to do is retrieve the list of column 1 values that have a certain value in column 2. For instance, if the lookup value for column 2 was 1, I would want A and B to match, but not C. Best case scenario, I could generate a new column containing the matches. Is there a way to do this without resorting to VBA?
EDIT:
The data I am working with is not so clean, here's a doctored version of it
1 2 3 4
83 Fun Edit ZZZZZZ*AAAAAA 210
365,400 176
210
85 Fun Edit 600,500 205
MEDICARE[705] 176
200
The extracted data does not like to preserve relationships between data beyond the column 1 identifier. In this case, the information in column 3 "###, ###" comes from item 176 in column 4. So filling down and taking the row will result in issues downstream.
In the long run, the data in column 4 is just a key for matching the information in this extract with another one.
I appreciate everyone's help thus far, and apologize for my insufficient original example.
Here's a short workflow that will do it:
Select the entire range
Press Ctrl+G (Goto)
Click Special
Tick Blanks and OK
Type = and arrow up. You should have a formula that looks like =A1
Press Ctrl+Enter. At this point all the missing alpha values should be filled in.
Apply Autofilter and filter the numbers to show only 1
If you want to use the filtered alpha list elsewhere, copy the values showing, and paste elsewhere.

How can I sort one set of data to match another set of data in Excel?

I have a list of data that is not in alphabetical or numerical order. I want to sort a second list of the same date to match the first list. I cannot change the order of the data. My goal is to paste additional data from the second set back into the first data set.
**DATA SET A** **DATA SET B**
22350 ____ BH160 100
22355 ____ 22350 125
BH160 ____ BH190 200
BH190 ____ 22355 150
I would like to get the numerical value from column 2 of DATA SET B to show up in a new column of DATA SET A. For example, I want 125 to show up in line 1, column 2 of DATA SET 1.
My list contains about 200 unique numbers and I need to update it every week.
Can someone help me? Maybe with a macro that I could use each week?
You could also use INDEX MATCH, which is more "powerful" than vlookup. This would give you exactly what you are looking for:
You can use VLOOKUP.
Assuming those are in columns A and B in Sheet1 and Sheet2 each, 22350 is in cell A2 of Sheet1, you can use:
=VLOOKUP(A2, Sheet2!A:B, 2, 0)
This will return you #N/A if there are no matches. Drag/Fill/Copy&Paste the formula to the bottom of your table and that should do it.
You could also simply link both cells, and have an =Cell formula in each column like, =Sheet2!A2 in Sheet 1 A2 and =Sheet2!B2 in Sheet 1 B2, and drag it down, and then sort those two columns the way you want.
If they don't sort the way you want, put the order you want to sort them in another column and sort all three columns by that.
If you drag it down further and get zeros you can edit the =Cell formula to show "" IF there is nothing. =(if(cell="","",cell)
Cutting, pasting, deleting, and inserting rows is something to be weary of. #REF! errors could occur.
This would be better if your unique items change also, then all you would do is sort and be done.

Resources