SUBTOTAL(9,RANGE) Function with SUMIF statements

janema

Board Regular
Joined
Nov 28, 2022
Messages
152
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2011
  5. 2010
Platform
  1. Windows
  2. Mobile
Is there a way to use the Subtotal function with SUMIF statements? I want the file to show the total of data when it is filtered, but cannot seem to add in the Subtotal function into the current formula. Perhaps it's not possible. :(

The current formula is: =(SUMIFS(O:O,T:T,"Yes")*0.035)-SUMIFS(X:X,T:T,"Yes")

So, when the file is filtered, I want it to show the sum of column O if column T equals "Yes" and then subtract the sum of column X if column T equals "Yes"
Right now this pulls the SUM of the column, however, I want them to show as a SUBTOTAL so when I filter it by a leader, it shows the total for what is showing rather than the sum total of the entire file.

I hope that makes sense. Here is what the file looks like:

1737596871960.png


Thank you soooo much in advance for any guidance and help you can give me to figure this out. I've been trying out formulas for the past hour. 😭😭😭
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Consider:

Book1
AOTXYZAA
1LeaderSalaryMerit EligibilityNew SalaryCurrentFilter
2Amy1000Yes1100-100110-100110
3Bob2000Yes2200
4Amy3000Yes3300
5Bob4000Yes4400
6Cal5000No5500
7Diane6000Yes6600
8Amy7000No7700
9Amy8000Yes8800
10Bob9000Yes9900
11Bob10000Yes11000
12Cal11000Yes12100
13Diane12000Yes13200
14Amy13000Yes14300
15Bob14000No15400
16Amy15000Yes16500
17
18
19
20
Sheet3
Cell Formulas
RangeFormula
Z2Z2=(SUMIFS(O:O,T:T,"Yes")*0.035)-SUMIFS(X:X,T:T,"Yes")
AA2AA2=SUMPRODUCT(O2:O101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))*0.035-SUMPRODUCT(X2:X101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))


And when it's filtered:

Book1
AOTXYZAA
1LeaderSalaryMerit EligibilityNew SalaryCurrentFilter
2Amy1000Yes1100-100110-42600
4Amy3000Yes3300
8Amy7000No7700
9Amy8000Yes8800
14Amy13000Yes14300
16Amy15000Yes16500
17
18
19
20
Sheet3
Cell Formulas
RangeFormula
Z2Z2=(SUMIFS(O:O,T:T,"Yes")*0.035)-SUMIFS(X:X,T:T,"Yes")
AA2AA2=SUMPRODUCT(O2:O101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))*0.035-SUMPRODUCT(X2:X101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))


Note that the SUMPRODUCT formula does not use whole column references. SUMIFS is smart enough to know what the bottom used row is, SUMPRODUCT is not. So use a range that encompasses all of your data, and add 10% to allow for expansion. Make sure that all the ranges are the same size.

Also note that I used SEQUENCE in the formula, which is available in 365, and 2021 and newer versions of the perpetual licenses. If you need this formula in older versions of Excel, we can substitute the old ROW(INDIRECT("1:100"))-1 construct.
 
Upvote 0
Solution
A simplified version of that in AB2

25 01 23.xlsm
AOTXYZAAAB
1LeaderSalaryMerit EligibilityNew SalaryCurrentFilterFilter 2
2Amy1000Yes1100-100110-100110-100110
3Bob2000Yes2200
4Amy3000Yes3300
5Bob4000Yes4400
6Cal5000No5500
7Diane6000Yes6600
8Amy7000No7700
9Amy8000Yes8800
10Bob9000Yes9900
11Bob10000Yes11000
12Cal11000Yes12100
13Diane12000Yes13200
14Amy13000Yes14300
15Bob14000No15400
16Amy15000Yes16500
17
SUBTOTAL
Cell Formulas
RangeFormula
Z2Z2=(SUMIFS(O:O,T:T,"Yes")*0.035)-SUMIFS(X:X,T:T,"Yes")
AA2AA2=SUMPRODUCT(O2:O101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))*0.035-SUMPRODUCT(X2:X101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))
AB2AB2=SUM((O2:O101*0.035-X2:X101)*(T2:T101="Yes")*SUBTOTAL(103,OFFSET(A1,SEQUENCE(100),0,1,1)))


And when filtered:

25 01 23.xlsm
AOTXYZAAAB
1LeaderSalaryMerit EligibilityNew SalaryCurrentFilterFilter 2
2Amy1000Yes1100-100110-42600-42600
4Amy3000Yes3300
8Amy7000No7700
9Amy8000Yes8800
14Amy13000Yes14300
16Amy15000Yes16500
17
SUBTOTAL
Cell Formulas
RangeFormula
Z2Z2=(SUMIFS(O:O,T:T,"Yes")*0.035)-SUMIFS(X:X,T:T,"Yes")
AA2AA2=SUMPRODUCT(O2:O101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))*0.035-SUMPRODUCT(X2:X101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))
AB2AB2=SUM((O2:O101*0.035-X2:X101)*(T2:T101="Yes")*SUBTOTAL(103,OFFSET(A1,SEQUENCE(100),0,1,1)))
 
Upvote 0
Consider:

Book1
AOTXYZAA
1LeaderSalaryMerit EligibilityNew SalaryCurrentFilter
2Amy1000Yes1100-100110-100110
3Bob2000Yes2200
4Amy3000Yes3300
5Bob4000Yes4400
6Cal5000No5500
7Diane6000Yes6600
8Amy7000No7700
9Amy8000Yes8800
10Bob9000Yes9900
11Bob10000Yes11000
12Cal11000Yes12100
13Diane12000Yes13200
14Amy13000Yes14300
15Bob14000No15400
16Amy15000Yes16500
17
18
19
20
Sheet3
Cell Formulas
RangeFormula
Z2Z2=(SUMIFS(O:O,T:T,"Yes")*0.035)-SUMIFS(X:X,T:T,"Yes")
AA2AA2=SUMPRODUCT(O2:O101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))*0.035-SUMPRODUCT(X2:X101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))


And when it's filtered:

Book1
AOTXYZAA
1LeaderSalaryMerit EligibilityNew SalaryCurrentFilter
2Amy1000Yes1100-100110-42600
4Amy3000Yes3300
8Amy7000No7700
9Amy8000Yes8800
14Amy13000Yes14300
16Amy15000Yes16500
17
18
19
20
Sheet3
Cell Formulas
RangeFormula
Z2Z2=(SUMIFS(O:O,T:T,"Yes")*0.035)-SUMIFS(X:X,T:T,"Yes")
AA2AA2=SUMPRODUCT(O2:O101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))*0.035-SUMPRODUCT(X2:X101,--(T2:T101="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))


Note that the SUMPRODUCT formula does not use whole column references. SUMIFS is smart enough to know what the bottom used row is, SUMPRODUCT is not. So use a range that encompasses all of your data, and add 10% to allow for expansion. Make sure that all the ranges are the same size.

Also note that I used SEQUENCE in the formula, which is available in 365, and 2021 and newer versions of the perpetual licenses. If you need this formula in older versions of Excel, we can substitute the old ROW(INDIRECT("1:100"))-1 construct.
 
Upvote 0
I tried the formula but got an error result. I tried both versions and no luck. :confused: Am I writing it wrong?

=SUMPRODUCT(O2:O600,--(T2:T600="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))*0.035-SUMPRODUCT(X2:X600,--(T2:T600="Yes"),SUBTOTAL(103,OFFSET(T2,SEQUENCE(100,,0),0,1,1)))

=SUMPRODUCT(O2:O600,--(T2:T600="Yes"),SUBTOTAL(103,OFFSET(T2,ROW(INDIRECT("1:100"))-1)))*0.035-SUMPRODUCT(X2:X600,--(T2:T600="Yes"),SUBTOTAL(103,OFFSET(T2,ROW(INDIRECT("1:100"))-1)))
1737664040199.png
 
Upvote 0
The ranges aren't the same size. O2:O600 and T2:T600 are the same size (599 cells), but the OFFSET(T2,SEQUENCE(100,,0),0,1,1)) range is only 100 cells. The size is determined by the 100 value in the SEQUENCE function. So try changing the 100 to 599. Same with the ROW(INDIRECT( version.
 
Upvote 0
The ranges aren't the same size. O2:O600 and T2:T600 are the same size (599 cells), but the OFFSET(T2,SEQUENCE(100,,0),0,1,1)) range is only 100 cells. The size is determined by the 100 value in the SEQUENCE function. So try changing the 100 to 599. Same with the ROW(INDIRECT( version.

Thank you so much! Does the 103 stay as 103 in the SUBTOTAL formula?

SUBTOTAL(103,OFFSET(T2,SEQUENCE(599,,0),0,1,1)))
 
Upvote 0
The ranges aren't the same size. O2:O600 and T2:T600 are the same size (599 cells), but the OFFSET(T2,SEQUENCE(100,,0),0,1,1)) range is only 100 cells. The size is determined by the 100 value in the SEQUENCE function. So try changing the 100 to 599. Same with the ROW(INDIRECT( versio

It worked!! You are AMAZING! Thank you so much. ❤️❤️❤️
 
Upvote 0
I tried both versions and no luck.
It seems that you tried both versions of the SUMPRODUCT suggestion. Did you try the much shorter SUM option from post 5?

Also, if you are marking a solution post, please mark the post that actually contains the solution to help future readers. Post 6 does not contain a solution to the original problem so I have removed the solution mark from that post.
 
Upvote 0
It seems that you tried both versions of the SUMPRODUCT suggestion. Did you try the much shorter SUM option from post 5?

Also, if you are marking a solution post, please mark the post that actually contains the solution to help future readers. Post 6 does not contain a solution to the original problem so I have removed the solution mark from that post.
Thanks. His original solution worked, I just had to fix a part of the formula and his response contained that solution. I updated and marked the original as the solution.
 
Upvote 0

Forum statistics

Threads
1,225,897
Messages
6,187,708
Members
453,435
Latest member
U4US

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