Sum column according to header and matched value

thanksamillion101

New Member
Joined
Jul 8, 2020
Messages
41
Office Version
  1. 2010
Hello and thank you ahead of time! I am needing to sum columns according to specified header names, reason being that I cannot specify a column range because the amount of columns may change when I run a report, but header names will remain the same. I need a formula to sum the amount of Units of Product "I" sold in TX with an Id of 375 between (Id 1) 350 and (Id 2) 400. The answer is 4.0 I have tried several formulas and now I am not sure which formula to use, sumif and index and match. Please help!

INDEX(A2:G7,MATCH("I",INDEX(A2:G7,MATCH("Product",A1:G1,0),),0))

ABCDEFG
1DateId 1Id 2NameProductUnitsState
21/1/2022100200SamAG2.5KS
33/4/2021600700TimEZ1.3OK
45/6/2021350400JohnI4TX
51/7/2021500700SamAG7.5KS
63/4/2022250400TimEZ6OK
75/1/2022600705JohnI8TX
 
That's great!...I'm happy to help.
Hello,
I forgot to mention, "Product" (Column E) may have more than one possibility of product (Ex. I, I+, or I-) and will need to sum all possibilities at times, so I tried to use a wildcard and it is not working with the formula, please help! ,,MATCH("Product",$A$1:$I$1,0))=$L$3&"*")* and this one ,,MATCH("Product",$A$1:$I$1,0))="*"&$L$3&"*")*
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I think you'll need to use INDEX/MATCH to return to correct column, but then pass that column into a function that accepts a wildcard. For example, SEARCH...like this:
MrExcel_20220803.xlsx
ABCDEFGHIJKL
1DateId 1Id 2NameProductUnitsStateFilters
21/1/2022100200SamAG2.5KSID601
33/4/2021600700TimEZ1.3OKProductI
45/6/2021350800JohnI+4TXStateTX
51/7/2021500700SamAG7.5KSSum12
63/4/2022250400TimEZ6OK
75/1/2022600705JohnI-8TX
Sheet2
Cell Formulas
RangeFormula
L5L5=SUMPRODUCT(INDEX($A$2:$I$99,,MATCH("Units",$A$1:$I$1,0)),ISNUMBER(SEARCH($L$3&"?",INDEX($A$2:$I$99,,MATCH("Product",$A$1:$I$1,0))))*(INDEX($A$2:$I$99,,MATCH("State",$A$1:$I$1,0))=$L$4)*(INDEX($A$2:$I$99,,MATCH("Id 1",$A$1:$I$1,0))<=$L$2)*(INDEX($A$2:$I$99,,MATCH("Id 2",$A$1:$I$1,0))>=$L$2) )

This assumes there is a single character after the product string. You can also incorporate a "*" if any number of characters could follow, but that might accept some products that should not be considered.

EDIT:
I'm concerned about mismatches with wildcards. Are the modifiers always single characters?...always at the end?...are they attached to the product code with a consistent character (hyphen, colon, etc.)?
 
Last edited:
Upvote 0
I think you'll need to use INDEX/MATCH to return to correct column, but then pass that column into a function that accepts a wildcard. For example, SEARCH...like this:
MrExcel_20220803.xlsx
ABCDEFGHIJKL
1DateId 1Id 2NameProductUnitsStateFilters
21/1/2022100200SamAG2.5KSID601
33/4/2021600700TimEZ1.3OKProductI
45/6/2021350800JohnI+4TXStateTX
51/7/2021500700SamAG7.5KSSum12
63/4/2022250400TimEZ6OK
75/1/2022600705JohnI-8TX
Sheet2
Cell Formulas
RangeFormula
L5L5=SUMPRODUCT(INDEX($A$2:$I$99,,MATCH("Units",$A$1:$I$1,0)),ISNUMBER(SEARCH($L$3&"?",INDEX($A$2:$I$99,,MATCH("Product",$A$1:$I$1,0))))*(INDEX($A$2:$I$99,,MATCH("State",$A$1:$I$1,0))=$L$4)*(INDEX($A$2:$I$99,,MATCH("Id 1",$A$1:$I$1,0))<=$L$2)*(INDEX($A$2:$I$99,,MATCH("Id 2",$A$1:$I$1,0))>=$L$2) )

This assumes there is a single character after the product string. You can also incorporate a "*" if any number of characters could follow, but that might accept some products that should not be considered.

EDIT:
I'm concerned about mismatches with wildcards. Are the modifiers always single characters?...always at the end?...are they attached to the product code with a consistent character (hyphen, colon, etc.)?
The modifiers will not always be single characters and will not always be at the ends, could be at the beginning as well, they are not attached with a consistent character. (aaI, bI, 2I, I+, I- )
 
Upvote 0
I think you'll need to use INDEX/MATCH to return to correct column, but then pass that column into a function that accepts a wildcard. For example, SEARCH...like this:
MrExcel_20220803.xlsx
ABCDEFGHIJKL
1DateId 1Id 2NameProductUnitsStateFilters
21/1/2022100200SamAG2.5KSID601
33/4/2021600700TimEZ1.3OKProductI
45/6/2021350800JohnI+4TXStateTX
51/7/2021500700SamAG7.5KSSum12
63/4/2022250400TimEZ6OK
75/1/2022600705JohnI-8TX
Sheet2
Cell Formulas
RangeFormula
L5L5=SUMPRODUCT(INDEX($A$2:$I$99,,MATCH("Units",$A$1:$I$1,0)),ISNUMBER(SEARCH($L$3&"?",INDEX($A$2:$I$99,,MATCH("Product",$A$1:$I$1,0))))*(INDEX($A$2:$I$99,,MATCH("State",$A$1:$I$1,0))=$L$4)*(INDEX($A$2:$I$99,,MATCH("Id 1",$A$1:$I$1,0))<=$L$2)*(INDEX($A$2:$I$99,,MATCH("Id 2",$A$1:$I$1,0))>=$L$2) )

This assumes there is a single character after the product string. You can also incorporate a "*" if any number of characters could follow, but that might accept some products that should not be considered.

EDIT:
I'm concerned about mismatches with wildcards. Are the modifiers always single characters?...always at the end?...are they attached to the product code with a consistent character (hyphen, colon, etc.)?
No errors are returned with this formula, but there is no sum returned and cell returns blank.
 
Upvote 0
Select the cell with the formula. Then click in the formula bar, hit F2 to enter editing mode, and then click Ctrl-Shift-Enter simultaneously to reconfirm the formula as an array formula. You should see curly brackets automatically wrap around the formula. Does it work then?
 
Upvote 0
Select the cell with the formula. Then click in the formula bar, hit F2 to enter editing mode, and then click Ctrl-Shift-Enter simultaneously to reconfirm the formula as an array formula. You should see curly brackets automatically wrap around the formula. Does it wor
 
Upvote 0
Select the cell with the formula. Then click in the formula bar, hit F2 to enter editing mode, and then click Ctrl-Shift-Enter simultaneously to reconfirm the formula as an array formula. You should see curly brackets automatically wrap around the formula. Does it work then?
Yes that was done and formula is an array formula with brackets and cell still returns blank.
 
Upvote 0
Have you installed the XL2BB add-in that will allow you to attach a small working sample of your worksheet? It's difficult to diagnose the problem without being able to see the issues. You can investigate the arrays produced by each of the logical tests to determine which one(s) are not working as expected. To do that, go back into the formula bar and select just the logical test to interrogate e.g., ISNUMBER(SEARCH($L$3&"?",INDEX($A$2:$I$99,,MATCH("Product",$A$1:$I$1,0))))
...and then hit F9 to see which rows have been identified as satisfying the criterion. When you are done looking, do not hit enter...just hit escape to preserve the array formula and prevent the intermediate exposed array from overwriting the formula.
 
Upvote 0
Select the cell with the formula. Then click in the formula bar, hit F2 to enter editing mode, and then click Ctrl-Shift-Enter simultaneously to reconfirm the formula as an array formula. You should see curly brackets automatically wrap around the formula. Does it work then?
I replaced the "?" ISNUMBER(SEARCH($L$3&"?",INDEX($A$2:$I$99,,MATCH("Product",$A$1:$I$1,0)))) with an "*" and it worked! ISNUMBER(SEARCH($L$3&"*",INDEX($A$2:$I$99,,MATCH("Product",$A$1:$I$1,0))))
 
Upvote 0
I'm glad you got it figured out...what terms were you looking for where this made a difference? The * is a wildcard for any number of characters. The risk is that if you search for I* and have products of I+ and I- and I that should be found (and none others), others such as AGI, AIBC, I65D, would be found too. That's why I'm wondering if SEARCH is the best approach, but without understanding what your actual product codes look like, I can't say one way or the other.
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top