Sum values using lookup table, where lookup values are a list of values with comma delimiter - excel

I am trying to sum values based that equal a lookup value. However, that value is actually a list of values delimited by a comma. Below is an example of what I mean.
Suppose I have raw data in the form of sheet1 below:
Sheet1:
A
B
1
ID
VALUE
2
A
30
3
A
50
4
A
20
5
B
10
6
B
20
7
C
70
8
C
40
9
D
30
10
E
50
11
F
20
12
F
30
13
G
10
And I have a look table that groups all IDs by their respective teams, as per sheet2 below.
Sheet2:
A
B
1
TEAM
IDS
2
Red
A, B
3
Blue
C, D
4
Green
E, F, G
And I want to create a report where the user can select the team name, and the sum of the values in sheet1 will aggregate based on the selection, as per the following example. So the user would select "Green" in cell B1 and it would return the sum of values that correspond to E, F, and G in sheet1.
Report:
A
B
1
Select Team:
Green
2
Sum:
110
I have searched all over for a solution to this and was able to find something similar. I tried to repurpose the formula for my data but couldn't get it to work because I think that solution dealt with numbers rather than text.
Excel: Perform a SUMIF where the criteria is a comma-delimited list
Any suggestions would be greatly appreciated!
Edit: Just want to add that I realize I could first parse out the IDs in sheet2, however I'm looking for a formula that can bypass that as my real dataset is quite large and parsing out the IDs under each team would explode the number of rows.

A variation of #JvdV solution on the linked question:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,FILTERXML("<t><s>"&SUBSTITUTE(VLOOKUP(Sheet2!F1,Sheet2!A:B,2,FALSE),",","</s><s>")&"</s></t>","//s")))
Note, this only works with Excel 2013 or later and only on PC. FILTERXML is not available on Mac or prior to 2013.
If Mac or prior to 2013:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,TRIM(MID(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",REPT(" ",999)),(ROW($ZY1:INDEX($ZY:$ZY,LEN(VLOOKUP(F1,Sheet2!A:B,2,FALSE))-LEN(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",""))+1))-1)*999+1,999))))

Related

Ignore text values in subtotal function

Excel-Sheet:
A B C D E
1 1.200
2 Product A 500
3 Product B 400
4 Product C OK
5 Product D #NA
6 Product E 300
7
8
In the above table I have list of products in Column A and some data about the products in Column B.
In Cell B1 I want to calculated the subtotal of Column B using =SUBTOTAL(9,B2:B6).
However, now I have the issue that Column B not only consists of numbers.
It can also have the data type text (OK, NA). Therefore, the result in Cell B1 currently is #NA.
Is there any kind of formula that I could use so only the number data is considered and the result is 1.200 as in the table above?
Please note:
This function =AGGREGATE(9,6,B2:B6) won't help me because I want to filter the list later on so I need to go with the SUBTOTAL.
Use 7 as the second criterion in AGGREGATE instead of 6 as it will also exclude hidden rows:
=AGGREGATE(9,7,B2:B6)
You can solve this, combining the Excel worksheet functions =Value() and =IfERROR():
The function =Value() gives the value of a number, and in case of text it gives an error.
=IfError() can be used to give 0 in that case.
So, imagine you have following situation:
Column A Column B Column C
1 =Value(A1) =IfError(B1;0)
3.5 =Value(A2) =IfError(B2;0)
AB =Value(A3) =IfError(B3;0)
abc10 =Value(A4) =IfError(B4;0)
This gives following results:
Column A Column B Column C
1 1 1
3.5 3.5 3.5
AB #Value 0
abc10 #Value 0
You can simply take the sum of column C.
So this is based on the summary in B1.
=SUM(IF(ISERROR(B2:B6),"",B2:B6))
You need to push Ctrl+Shft+Enter for this to work.
Hope it helps.

Assign one value at the time from a column i Excel if the value is the same

I got some help with a problem finding column values in Excel: Find column value Excel
The table looks like this:
A 17 8,5 5,666666667 4,25 3,4 2,833333333 2,428571429
B 5 2,5 1,666666667 1,25 1 0,833333333 0,714285714
C 5 2,5 1,666666667 1,25 1 0,833333333 0,714285714
G 4 2 1,333333333 1 0,8 0,666666667 0,571428571
The code that I got help with basically selects A, B, C and G based of the order of the largest numeric value. The largest value is 17, that is one point for A, then comes 8,5 which gives another point for A. That works fine.
However, then comes 5. I now get B two times instead of first B and the C (the order does not matter, but I do not want to get two points for B when B and C have the same value). How can this be fixed?
(The real problem that this example illustrates is the number of seats on local boards in Swedish multiplicitets, where the number of seats for the different parties is based on the number of seats in the city council.)
Edit: Formula: =INDEX($J$16:$J$25,AGGREGATE(14,6,ROW($K$16:$W$25)/(K28=$K$16:$W$25),1)-ROW($J$16)+1)
Edit2: Wanted result:
Mandate Party
1 A
2 A
3 A
4 B
5 C
To do this by formulas, I think a simple way is to
unpivot the original data using formulas
Apply a unique rank formula to that data
Then use VLOOKUP to return ranks 1-n
The following formulas and defined names will be useful
origTbl =Sheet2!$A$1:$H$4
unpivotTbl =Sheet2!$A$8:$C$35
A8 =RANK(C8,$C$8:$C$35,0)+COUNTIF($C$8:C8,C8)-1
B8 =INDEX(origTbl,INT((ROWS($1:1)-1)/7)+1,1)
C8 =INDEX(origTbl,INT((ROWS($1:1)-1)/7)+1,MOD(7+ROWS($1:1)-1,7)+2)
Fill down A8:C8 to row 35
In the formulas in B8 and C8, the 7 is the number of columns in origTbl minus 1 (eg: COLUMNS(origTbl)-1)
Any changes you make in origTbl will be reflected in the final table
For appearances, you can certainly hide the UnPivot table someplace.
Note: in my locale, decimal separator is the dot

Excel to sum value of duplicates while retaining its duplicate text

I need help on a loooong list of values that is possibly having duplicates with its quantity needed to sum however while retaining its duplicates.
Hard to explain, example of scenario and goal I'd like to achieve.
Please help.
Current Situation
material value
a 10
b 10
a 10
c 10
c 10
a 10
b 10
b 10
b 10
Goal to Achieve
material value
a 30
b 40
a 30
c 20
c 20
a 30
b 40
b 40
b 40
Something like above. I'm jumbled up with the formulas. Please help!
One important point to consider here: First, because you need to sum values AND change the values you're summing, you're going to get a circular reference if you try to do this dynamically.
One way to get around this is to add a third column, with the formula =SUMIF(A:A,A1,B:B)
If you absolutely need the values in column B, just copy from C, then paste the values, or just hide column B.

EXCEL match 2 columns against each other

I have two columns of data, they look something like this:
A B C D
1 2 SOME RECORD
2 6 SOME RECORD
3 10 SOME RECORD
4
5
6
7
8
9
10
So basically column A is a list of indices, where some of them appear in column C with corresponding records saved in column D. Column B is currently empty, and what I want to do is if say index 2 appears in both column A and column C (they matches), then put the record beside C2 in the cell B2. So essentially I want it to look like this:
A B C D
1 2 SOME RECORD
2 SOME RECORD 6 SOME RECORD
3 10 SOME RECORD
4
5
6 SOME RECORD
7
8
9
10 SOME RECORD
Can someone help please?!! Thanks!!!
UPDATE: I tried this and it doesn't work. The data in column D is calculated using a UDF and is refreshing every 1 second. The VLOOKUP function fails even though I can see the 2 indices are the same!! Is it because of the format of the cell or column? I.e. does vlookup compare data type as well?
Assuming your data in A starts from A1 - put in B1 the following and autofill:
=IFERROR(VLOOKUP($A1,$C:$D,2,0),"")
This includes handling of missing values.
You'll want this:
B1=VLOOKUP(A1, C:D, 2, FALSE)
This will look up the value in column A within the array spanning columns C and D. It will give you the value found in the second column (D). FALSE makes it an exact match, otherwise you might get 2 and 20 matching because hey, they're kind of similar...

Dynamically set cell values from table in Excel

I've got an excel document that essentially looks like this (imagine it having around 15 000 rows):
A B C D E F
---------------------------
Art Price Art Price
---------------------------
A 1 A 5
A 3 B 10
A 4 C 8
B 7
B 2
C 3
C 15
As you can see the prices in column B are inconsistent.
What I want to do is to set the prices (in column B) to the correct prices (that are found in column E) based on the articles name (found in column A and D).
Unfortunately I'm at loss when it comes to VBA in Excel, and formulas in Excel, what would be a smart way to approach (or solve) this?
Thank you in advance!
Try the VLOOKUP excel formula in the excel help, no coding needed.
Enter =VLOOKUP(A2;$D$2:$E$4;2) in cell B2 and fill down.

Resources