VLookup with multiple results adding values - excel

I would like to lookup a value in another excel file that will have multiple results as rows. For example If the specific value is found in the column A of that row I want to add the number in column c to a total and then output that.
Book 1 VLookup from this sheet :
Book 2 Vlookup destination:
Desired Result:
I would normally add what I have tried, but im completely stumped, the only real formula ive tried is a standard VLookup. The Watered down question is "Need to know: how many sales per unique sku?"

As #BigBen suggested in the comment, use =SUMIF() formula.
in a pseudocode: =SUMIF(range_to_check, product_name, sales_amount_range)
So with the following data:
The formula in E1 which you can drag to other cells in the column would look like:
=SUMIF(A1:A6, D1, B1:B6)

Related

Excel averageifs by looking up column for criteria

I have a spreadsheet that looks like this:
The data is in the coloured section, to the right of that is a table that shows the average of the result column when the data under ABC, XYZ, or GGG is inbetween the Max and Min Value.
This was done with this formula: =AVERAGEIFS($D$4:$D$27,A$4:A$27,"<"&$F5,A$4:A$27,">"&$G5)
What I want to do is have that formula reference the heading and then lookup the appropriate column in the data table to apply the averageif criteria to.
The formula I have now works fine but as I add more columns and the data table that may be out of order it would be much better if I was able to incorporate a lookup or match into the averageifs formula.
The following non-volatile function will do it:
=SUMPRODUCT(($A$1:$C$1=H$1)*($A$2:$C$21>=$G2)*($A$2:$C$21<=$F2)*($A$2:$C$21))/SUMPRODUCT(($A$1:$C$1=H$1)*($A$2:$C$21>=$G2)*($A$2:$C$21<=$F2))
EDIT
To get the average of the results column when the other column is within the constraints. Change the fourth Criterion in the first SUMPRODUCT():
=SUMPRODUCT(($A$1:$C$1=H$1)*($A$2:$C$21>=$G2)*($A$2:$C$21<=$F2)*($D$2:$D$21))/SUMPRODUCT(($A$1:$C$1=H$1)*($A$2:$C$21>=$G2)*($A$2:$C$21<=$F2))
EDIT2
Another option that is both non volatile and non array:
=AVERAGEIFS(D:D,INDEX(A:C,0,MATCH(H$1,1:1,0)),">=" & G4,INDEX(A:C,0,MATCH(H$1,1:1,0)),"<=" &F4)
if you are doing it over a small number of calcs then the Offset function will work for you replace your reference to your current A column with
OFFSET($A$4,0,MATCH(h$2,$a$2:$d$2,0))-1,24,1)
The offset is broken down in to $A$4 being your reference point.
The 0 being how many rows to move from the reference point to start
The MATCH(h$2,$a$2:$d$2,0))-1 being how many columns to move from the reference point
The 24 is the number of rows to return
The 1 is how many columns to return
The match formula looks for the value in H2 in your header road in A2:D2 for an exact match and returns the number for the spot the item was found. We subtract 1 from this result as we only want to move one less spot than where the item was found. So it if was found in the 1st spot we dont want to move over any columns so we need to make the value 0.
You end formula would look something like:
=AVERAGEIFS($D$4:$D$27,OFFSET($A$4,0,MATCH(h$2,$a$2:$d$2,0))-1,24,1),"<"&$F5,OFFSET($A$4,0,MATCH(h$2,$a$2:$d$2,0))-1,24,1),">"&$G5)

Returning multiple column headers values using multiple matching criteria

I am looking for returning multiple column values using multiple matching criteria.
Attached is a screenshot of sample sheet, which have my criteria on cell's B1 & C1.
So basically, when matching 2 criteria (example "Team1" & "low"), it should return columns header (example Name10 & name14) from the header ranger C3:N3.
I have tried a couple of formulas, and is is how far I gone: =INDEX($C$2:$AL$2,SMALL(IF(($A$3:$A$21=$B$1)*($B$3:$B$21=$C$1),ROW($A$3:$A$21)-ROW($A$3)+1),ROW(1:1)))
I am not sure what is missing?
enter image description here
enter image description here
Thanks in advance
Fox
First of all, in your example you point out row 3 and 4 but only one of the specified criteria are matched in this rows: low, because Team4 specifyed in the criteria it's not matched, so i will consider you are looking to match one OR both the criteria specified.
The only way i can imagine for do this with a formula is to use a formula like this
=SE(C3<>0;$C$2&", ";"")&SE(D3<>0;$D$2&", ";"")&SE(E3<>0;$E$2&", ";"")&SE(F3<>0;$F$2&", ";"")&SE(G3<>0;$G$2&", ";"")&SE(H3<>0;$H$2&", ";"")&SE(I3<>0;$I$2&", ";"")&SE(J3<>0;$J$2&", ";"") 'and so on...
where SE() it's function IF() in my language, with this formula in a column on the right of the table (for example col O) you will have a list of the names of that row where the corresponding number is different from 0...expand the formula down for all the rows and then, with a formula like this
=SE(O(A1=A3;B1=B3);O3;"")&SE(O(A1=A4;B1=B4);O4;"")&SE(O(A1=A5;B1=B5);O5;"")&SE(O(A1=A6;B1=B6);O6;"")&SE(O(A1=A7;B1=B7);O7;"") 'and so on...
with the function O() corresponding to OR() you will concatenate the strings (names) of the rows that match one OR both the criteria. If you whant to match both the criteria you should use AND() instead of OR().
The problem of this approach is that the formula becomes very long if you have a lot of names and a lot of rows, and if you add rows you have to modify the formula. Another problem is that if you match the same name more times it will be repeated in the list that the formula outputs...and the list of the names ends with a comma.
In fact, i can't tell that this is a good way for obtain what you need, but it's the only i can imagine only with formulas.
If you should use a macro the problem would be solved better and in a more flexible way, should you?

Excel Formula not accepted but no reason for error

I have a if formula with a number of criterias it has to match.
When I have shortened the formula down it works from beyond - IF(LEFT(A6,1)="2"
but there are no reasons it should error at this point? Any help?
=IF(LEFT(A6,2)="10","Area 1",IF(LEFT(A6,2)="12","Area 2",IF(LEFT(A6,2)="13","Area 3",IF(LEFT(A6,2)="14","Area 4",IF(LEFT(A6,2)="15","Area 5",IF(LEFT(A6,2)="16","Area 6",IF(LEFT(A6,2)="17","Area 7",IF(LEFT(A6,1)="2","Bulk",IF(LEFT(A6,1)="4","Intl",IF(LEFT(A6,2)="7","CGCC","Ad-Hoc"))))))))))
You can try combining IF and VLOOKUP.
=IF(LEFT(A6,1)="4","Intl",IF(ISNA(VLOOKUP(LEFT(A6,2),{"7","CGCC";"10","Area 1";"12","Area 2";"13","Area 3";"14","Area 4";"15","Area 5";"16","Area 6";"17","Area 7"},2,FALSE)),"Ad-Hoc",VLOOKUP(LEFT(A6,2),{"7","CGCC";"10","Area 1";"12","Area 2";"13","Area 3";"14","Area 4";"15","Area 5";"16","Area 6";"17","Area 7"},2,FALSE)))
I embedded the array in the formula but you can prepare a table (assume G1:H7) like this:
and then use the VLOOKUP with the reference:
=IF(LEFT(A6,1)="4","Intl",IF(ISNA(VLOOKUP(LEFT(A6,2),G1:H7,2,FALSE)),"Ad-Hoc",VLOOKUP(LEFT(A6,2),G1:H7,2,FALSE)))
IFNA or IFERROR could also be used but they are not available in Excel 2003.
Your entire formula could be shortened to 2 VLOOKUP functions, by putting your data into a table, with your ID column on, say, column A of sheet2, and your results column on column B of sheet2. This would look as follows:
=IFERROR(VLOOKUP(LEFT(A6,2),'Sheet2'!A:B,2,0),IFERROR(VLOOKUP(LEFT(A6),'Sheet2'!A:B,2,0),"Ad Hoc"))
What this does is: first try to match the left 2 characters in A6 to one of your ID's in column A in sheet2. If that creates an error, it tries to match the left 1 character in A6 to one of your ID's in column A of sheet2. Either way, it returns the matching value in column B of sheet2. If no match is found, it returns "Ad Hoc".

Excel complicated count function

I have kind of a complicated count I can't seem to figure out. Basically I have a table that looks similar to this image:
Now what I need to do is:
Tally the number of 1's if the category = "Anon" in one cell, then count the number of 2's and 3's in separate cells all if the category = "Anon".
Wash/Rinse/Repeat for if it's "Watterson" and "Davis".
Is there any way I can count the occurrences of 1|2|3 and have it separated by category like this?
Sorry, kind of an Excel noob here. I didn't think pivot tables would be correct though (especially because they want the dates to be columns, plus I couldn't figure out how to insert a conditional). Any pointers in the right direction would be appreciated.
Let's suppose that your screenshot shows cells A1:I6.
Then ...
Add column headings "1", "2", "3" in cells J1:L1
Put the formula =COUNTIF($C2:$I2,J$1) into J2 and copy it across and down
Set up a list of unique Categories (Anon, Watterson etc) starting in A10
Add headings in row 9 like "Category", "Tally of 1s", "Tally of 2s", "Tally of 3s"
Put the formula =SUMIF($B$2:$B$6,$A10,J$2:J$6) into B10 and copy it across and down
My guess is that someone cleverer than I could construct a sumproduct formula for B10 that works without the need for the helper columns J:L.
[Edit] Using Maki's sumproduct formula in my structure, you can scrap helper values in cols J:I and put this into B10 -- =SUMPRODUCT(($B$2:$B$6=$A10)*($C$2:$I$6=B$9))
assuming that you start from cell A1,
=SUMPRODUCT((list name to search for)*(value to search in the data area))
=SUMPRODUCT(($B$2:$B$6="Anon")*($C$2:$I$6=1))
=SUMPRODUCT(($B$2:$B$6="Anon")*($C$2:$I$6=2))
...
=SUMPRODUCT(($B$2:$B$6="Watterson")*($C$2:$I$6=1))
...etc.

How to use VLOOKUP in this situation?

Here's what I'm trying to do with no success.
I have 2 sheets in a workbook. Format and TC.
Format looks something like this:
And TC looks something like this
I want to add after the last column in Format another column where to add the values that are in the 10th column of the TC value. That if the 2nd columns in both are the same.
This is how I tried to do it and it seems it doesn't work and I really don't know why since I'm an absolute beginer with VLOOKUP.
=IF(VLOOKUP(B2;TC!B:B;TC!V:V;FALSE)= "Montaj (Montage)"; "here I want to select the time and I don't know how…"; "VALUE NOT FOUND")
To explain it better... if the value of one cell in column 2(B) in the Format sheet is found in TC sheet in column 2(or B) then if the value of the 4th column (V) is "Montaj (Montage)" I want to put the value in the 10th column (235 in the example).
Thanks a lot for your help!
FINAL UPDATE: Added explanation.
What you need is SUMIFS. I fixed this to match your comment below.
=SUMIFS(TC!Z:Z,TC!B:B,Format!B2,TC!J:J,"Montaj (Montage)")
This will look in the B column in the TC sheet and look for the value in B2 of the Format sheet. If it finds it, AND it finds "Montaj (Montage)" in the same row in the J column, then it will return(sum if there are more than one match) value in the SAME ROW in the J column.
SUMIF is really convenient for summing conditions like this. If you only have 1 condition, you can use SUMIF. VLookup is similar, but it just returns a single value, it doesn't do anything with it.
Here is some helpful info on how SUMIFS works: http://office.microsoft.com/en-us/excel-help/sumifs-function-HA010047504.aspx

Resources