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
 
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.
These are the only product code options (aaI, bI, 2I, I+, I- ) and the "*" did not include all "I" product codes, therefore, since I know the only options, could I do a list with search, ex. ISNUMBER(SEARCH({aaI, bI, 2I, I+, I-},INDEX($A$2:$I$99,,MATCH("Product",$A$1:$I$1,0))))
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
It's a little more complicated than that. Is that what you want to do?....search for any of multiple product codes for a given input of State and ID number? The text strings to search for will need to be enclosed in quotes, but the bigger issue is that you will generate a multi-column array, one column for each of those search terms. And if you only want to know that any one of those terms has been found, then you'll need to convert the multi-column array into a single column array. Let me know and I'll offer an approach.
 
Upvote 0
Here is an example using an array of search terms. The MMULT function is needed to transform the multi-column array resulting from SEARCH into a single column array. To do that, we multiply that array by a single column array of 1's (which is little messy to do with an older version of Excel...but that's what this part of the formula does:
Excel Formula:
ROW(INDIRECT(1&":"&COUNTA({"aal","bl","2l","l+","l-"})))^0
MrExcel_20220803.xlsx
ABCDEFGHIJKL
1DateId 1Id 2NameProductUnitsStateFilters
21/1/2022100200SamAG2.5KSID601
33/4/2021600700TimEZ1.3OKProduct
45/6/2021350800JohnI4TXStateTX
51/7/2021500700Samaal7.5TXxSum23.5
63/4/2022250400TimEZ6OK
75/1/2022600705JohnI-minus8TX
83/4/2022250400Timaal6OK
95/1/2022600705Johnbl8TXx
103/4/2022250400Timl+6OK
115/1/2022600705Johnl-8TXx
123/4/2022250400TimEZ6OK
135/1/2022600705JohnI-minus8TX
14
Sheet2
Cell Formulas
RangeFormula
L5L5=SUMPRODUCT(INDEX($A$2:$I$13,,MATCH("Units",$A$1:$I$1,0)),MMULT(--ISNUMBER(SEARCH({"aal","bl","2l","l+","l-"},INDEX($A$2:$I$13,,MATCH("Product",$A$1:$I$1,0)))),ROW(INDIRECT(1&":"&COUNTA({"aal","bl","2l","l+","l-"})))^0)*(INDEX($A$2:$I$13,,MATCH("State",$A$1:$I$1,0))=$L$4)*(INDEX($A$2:$I$13,,MATCH("Id 1",$A$1:$I$1,0))<=$L$2)*(INDEX($A$2:$I$13,,MATCH("Id 2",$A$1:$I$1,0))>=$L$2) )
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:G13Expression=AND($B2<=$L$2,$C2>=$L$2,$G2=$L$4)textNO

I've added some conditional formatting to more easily pick out the matched rows and an "x" in column H identifies where the Product ID is found. Previously, I thought the letter that looks like a vertical line was a capital I as in "India", but is it a lower case case as in "like"?
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,867
Members
449,053
Latest member
Mesh

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