Totalling values with the same order ID in excel - excel

I have a large excel speadsheet with (amongst others) the following columns
orderId price
222 50.00
222 52.60
223 44.00
223 60.00
224 20.00
225 40.00
Is there a way to display the orderId as a Unique row with the sum of all prices under that id? So this example would result in
orderId price
222 102.60
223 104.00
224 20.00
225 40.00
I'm happy to create a macro to do the job if necessary (I have VB knowledge but haven't used it for years and I've never applied it to excel before)

This is easily solved via Pivot table unless i am mistaking your requirement.
Insert -> Pviot table
set as below

Although it's not a VBA solution, you can just copy and paste the Order ID column and use "remove duplicates" from the Excel ribbon to make a unique list. Then to the right of each entry, just put =SUMIF(A:A, C1, B:B), where A:A I assume is the order ID column, C1 is the first entry in the unique list, and B:B i assume is where the values are.
=SUMIF(what is the range you want to look through?, what do you want to look for?, where are the values you want to add up?)
For VBA, you could get fancy and use the dictionary object, simply entering each unique value you find in the object id column, and if it exists, then just add the total to the value for that entry. At the end, just use the .keys and .items to output the list. :)

Related

Excel function to sum all actual costs plus estimates on blank rows with no calculation column

In Excel 2013, I need to sum all numbers in a column of actual costs plus estimates in a second column in rows where the actual costs are blank.
Estimate (A) Actual (B)
Row 1 106
Row 2 212 230
Row 3 318 295
Row 4 424
totals 1060 525
I need to return 106 + 230 + 295 + 424. (or 525 + 106 + 424)
What I have tried:
--I have solved the problem if I put a placeholder (like "missing") in the blanks and then using a SUMIF nested in a simple SUM. But that badly clutters the chart.
=SUM(A5, SUMIF(B1:B4,"missing",A1:A4))
--I have also solved the problem by creating a calculation column that has an ISBLANK function and then using the SUMIF over that result. However, I can't figure out how to consolidate. I realize I could create another sheet to hold the calculation column, but the workbook will already have a number of sheets and I want to avoid an extra.
C1=ISBLANK(B1) dragged down to C4 and then =SUM(A5, SUMIF(C1:C4, "TRUE", A1:A4))
--I have found a number of online descriptions of managing similar tasks with pivot tables and months, but I can't seem to figure it out for a simple table.
I think my ISBLANK attempt is failing on consolidation because of something to do with absolute references vs. ranges in the column, but I can't figure it out.
Any advice would be greatly appreciated--thanks
Use SUMIF() to sum all numbers in column A if the value to the right is blank. Then add the sum of column B.
See this formula:
=SUMIF(B:B, "", A:A) + SUM(B:B)
Use array version of SUM(IF()):
=SUM(IF(B1:B4<>"",B1:B4,A1:A4))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Using INDEX, MATCH and COUNTIFS to filter and match data in Excel. Formula incorrect?

I am trying to use INDEX, MATCH and COUNTIFS in excel to filter for relevant data within 2 spreadsheets. However, the formula below only returns the first value of per the matched criteria and replicates this value throughout the identified rows:
IF(COUNTIFS(A:A,$A43,J:J,G$3),INDEX(L:L,MATCH(G$3,J:J,0))),"")
*Please see a sample of the criteria i am trying to match below. If the IDs and Names in table 1 and 2 are matched, display the % Allocated in Table 2. The problem i'm having is that the formula only matches Bill at 10% and displays 10% for every other matched name.
Table 1:
ID Name Project % Allocated
4121 Bill 30100 10%
4122 Murray 30200 30%
4123 Harmon 30300 50%
4132 John 30408 40%
Table 2:
ID Name Project % Allocated
4121 Bill 30100
4122 Murray 30200
4131 Shauna 30407
4132 John 30408
If ID is unique to both lists vlookup will work.
In Table2 % Allocated formula:
=vlookup(A2,Table1!A:D,4,0)
If unique combination is ID and Name as you state this array formula will work.
=INDEX(Table1!D:D,Match(A2&B2,Table!A:A&Table1!B:B,0))
Be sure to press Ctrl + Shift + Enter when exiting cell edit mode.
assume that Table1 and Table2 are on two separate sheets (named accordingly) in column A:D
Make a reference to the row number using row () +1. This will make it so that the range it is looking for becomes smaller and smaller as it works its way down the list. This will make it a dynamic formula. Can you show a picture of what you are trying to do. Right now the idea isnt all that tangible.

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.

EXCEL 2010, vertical search, parse cell

I need help with vertical search in Excel 2010.
I have a document with two sheets, in each sheet is one table containing data ...
sheet one
A B C D
123 sth sth 'need to find and copy value from second sheet(key is collumn A); formula here
321
678
845
983
sheet two
A B C
123, 321 sth 100 'looking for this value, copy 100 to first sheet to key 123 and also 321
678 99 'value for key 678 in sheet one
845, 983 82 'value for keys 845 and 983 in sheet one ..
I use vlookup(), but when I have two values separated with comma in one cell it doesn't work and I have to do it manually.
Is there a function something like vlookup which I can combine with left() and right() functions, or do I have to use something more sophisticated, a VB macro?
I cannot change layouts of these sheets ...
Thank you.
Use an array formula with SEARCH?
{=IF(SEARCH(A1,Sheet1!A:A),Sheet2!D:D)}
slightly more comprehensive version of that:
{=SUM(IF( NOT(ISERROR(SEARCH(A1,Sheet2!A:A))),Sheet2!D:D))}
as mentioned by Nanashi, you can change sum to average or whatever you like handle multiple values
You need to use ctrl+shift+enter to make a formula an array formula.
Rather hacky solution that uses formulas only.
Enter in Sheet1!C1:
=IF(COUNTIF(Sheet2!$A:$A,Sheet1!$A1)=1,VLOOKUP(Sheet1!$A1,Sheet2!$A:$C,3,FALSE),SUMIF(Sheet2!$A:$A,"*"&Sheet1!$A1&"*",Sheet2!$C:$C))
Sample result:
Sheet2
Sheet1
Disclaimer:
This method is very easy to break. One possible failing is that if there are no spaces between the IDs in Sheet2, the formula fails. Also, if by any chance the ID repeats in Sheet2, they will be added due to the usage of SUMIF. A workaround is to use AVERAGEIF instead.

Subtracting columns in a Vlookup

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)

Resources