Combine SUMIF and SUBTOTAL

nparsons75

Well-known Member
Joined
Sep 23, 2013
Messages
1,254
Office Version
  1. 2016
Hi,

I have a table of data with a 3 cells that calculate the sum of a column (C) depending on the value in the adjacent column (B). So, SUM all values that contain the correct criteria. I have 3 criteria options, r,a,g. Basically red amber green. The formula works fine and shows what I need. However, the next step which I need to work I cannot get to grips with. I would like to filter using the standard table dropdown and select a customer. The result would then show me the SUM only for that specific customer. To do this I think! I need to somehow combine SUMIF and SUBTOTAL. Please see the table below, hopefully this helps to explain. Appreciate any help...

Book1
ABCDEFGH
3SumSumSum
46700256012194244981695742
51695742
6CustomerRiskValue
7Davidr319844
8Davidr164511
9Davidg251458
10Davidg52320
11Marka104860
12Marka174600
13Markr97800
14Marka119000
15Marka99504
16Steveng28320
17Steveng92400
18Charliea102000
19Charliea1255
20Charlier75865
21Charlier12005
Sheet1
Cell Formulas
RangeFormula
E4E4=SUMIFS(C7:C21,B7:B21,"r")
F4F4=SUMIFS(C7:C21,B7:B21,"a")
G4G4=SUMIFS(C7:C21,B7:B21,"g")
H4H4=SUM(E4:G4)
C5C5=SUM(C7:C21)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B7:B21Cell Value="g"textNO
B7:B21Cell Value="a"textNO
B7:B21Cell Value="r"textNO
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Here's one way using a helper column. I personally prefer this way but it can be done without the extra column if needed, it just makes the formulas more complex.
For reference the formula for "r" without the helper column would be =SUMPRODUCT(SUBTOTAL(9,OFFSET(C7,ROW(C7:C21)-ROW(C7),))*(B7:B21="r"))
Helper in column D with results in E5:H5. Original formulas left in place for reference.
Book1
ABCDEFGH
3SumSumSum
46700256012194244981695742
51695742595764978004979640595764
6CustomerRiskValueValue
11Marka104860104860
12Marka174600174600
13Markr9780097800
14Marka119000119000
15Marka9950499504
Sheet1
Cell Formulas
RangeFormula
E4E4=SUMIFS(C7:C21,B7:B21,"r")
F4F4=SUMIFS(C7:C21,B7:B21,"a")
G4G4=SUMIFS(C7:C21,B7:B21,"g")
H4:H5H4=SUM(E4:G4)
C5:D5C5=SUM(C7:C21)
E5E5=SUMIFS(D7:D21,B7:B21,"r")
F5F5=SUMIFS(D7:D21,B7:B21,"a")
G5G5=SUMIFS(D7:D21,B7:B21,"g")
D11:D15D11=AGGREGATE(9,5,C11)
 
Upvote 0
Solution
You can add Customer name as additional Sumif Criteria. e.g.
E4=SUMIFS(C7:C21,B7:B21,"r",A7:A21,D1)
This way you can get your results without using the filter dropdown.

Additionally you can use data validation in cell D1 to make it easier for users to select Customer Names.

Or Use Pivot table to achieve your goal.


hth....
 
Upvote 0
@fadee2 The question asked for a way to get the desired results with the source data being filtered, which will require a formula that ignores hidden rows. SUMIFS doesn't ignore hidden rows.
 
Upvote 0
@jasonb75 I suggested a workaround, that is possible, since using sumif/pivot table, there is no need for the user to hide the rows, or use autofilter.
 
Upvote 0
Here's one way using a helper column. I personally prefer this way but it can be done without the extra column if needed, it just makes the formulas more complex.
For reference the formula for "r" without the helper column would be =SUMPRODUCT(SUBTOTAL(9,OFFSET(C7,ROW(C7:C21)-ROW(C7),))*(B7:B21="r"))
Helper in column D with results in E5:H5. Original formulas left in place for reference.
Book1
ABCDEFGH
3SumSumSum
46700256012194244981695742
51695742595764978004979640595764
6CustomerRiskValueValue
11Marka104860104860
12Marka174600174600
13Markr9780097800
14Marka119000119000
15Marka9950499504
Sheet1
Cell Formulas
RangeFormula
E4E4=SUMIFS(C7:C21,B7:B21,"r")
F4F4=SUMIFS(C7:C21,B7:B21,"a")
G4G4=SUMIFS(C7:C21,B7:B21,"g")
H4:H5H4=SUM(E4:G4)
C5:D5C5=SUM(C7:C21)
E5E5=SUMIFS(D7:D21,B7:B21,"r")
F5F5=SUMIFS(D7:D21,B7:B21,"a")
G5G5=SUMIFS(D7:D21,B7:B21,"g")
D11:D15D11=AGGREGATE(9,5,C11)

Thank you, this has worked perfectly....

I would also like to create a variation of the formula if possible?

=SUMPRODUCT(SUBTOTAL(9,OFFSET(C7,ROW(C7:C21)-ROW(C7),))*(B7:B21="r"))

Is it possible, where this is, "r" how could I replace this with something that instead of equalling r, replace with contains the text...."Car" for example...
 
Upvote 0
For that you would need to perform a search on the criteria.
Excel Formula:
=SUMPRODUCT(SUBTOTAL(9,OFFSET(C7,ROW(C7:C21)-ROW(C7),))*ISNUMBER(SEARCH("car",B7:B21)))
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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