SUBTOTAL, IF?

Texas Longhorn

Active Member
Joined
Sep 30, 2003
Messages
493
Is it possible to combine a subtotal into a sumif? Example: I have a large table of data in 10 columns, all with column headings. In the same sheet, in 20 rows above the table, I have summary boxes where I return values based on parameters (eg, what is license revenue for deals rated "A").

Further, I have an autofilter on the table. Now, when I filter, say for quarter 4 only, I want my summary boxes to update like a subtotal does (eg. ignores hidden rows). I tried SUMIF, but it includes rows hidden by the filter.

Any ideas?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Those are quite cool, but I'm not certain they solve my problem (maybe they do -- I'm pretty novice). I actually want the sum of all filtered rows, not just the first "x". However, I want the subtotal of column B (revenue) if Column A (Region) = South. It's a SUMIF, except I need it to update when I filter on column C (Quarter).

Thanks.
 
Upvote 0
rte-create the following:
Book2
ABCDE
1RegionSouth
2Sum26
3RegionRevenueQuarter
4North11
5South22
6East31
7North42
8South51
9East62
10North71
11South82
12East91
13North102
14South111
Sheet1


the formula in e2 is:

=SUMPRODUCT((SUBTOTAL(3,OFFSET(A4:A14,ROW(A4:A14)-MIN(ROW(A4:A14)),,1)))*((A4:A14)=E1)*(B4:B14))

...which needs to be entered with conrtol + shift + enter, not just enter.

Filter the data to show only quarter 1 - the sum for the south region is 16.
 
  • Like
Reactions: SR4
Upvote 0
Filter the list shown in rows 1:12 (below) based on 'Fruit' or 'Month' values and notice how the Salesman summary is affected...
Book1
ABCDEFGH
1FruitMonthSalespersonQtyField6Field7
2ApplesFebLarry11TRUE
3OrangesMarLarry202TRUE
4BananasFebMoe133TRUE
5GrapesFebCurly164TRUE
6LemonsJanCurly85TRUE
7ApplesMarLarry26TRUE
8OrangesMarMoe187TRUE
9BananasJanMoe178TRUE
10GrapesMarLarry79TRUE
11LemonsFebCurly610TRUE
12108
13
14SalespersonQty
15Larry30
16Moe48
17Curly30
18108
19
Sheet1
 
Upvote 0
Thanks--the formulas work great. That being said, I used PaddyD's formula, which does exactly what I need, but I have no idea what I told Excel to do (the more I'm here, the more I realize I define amateur). Could someone explain what the formula is doing?

Thanks.
 
Upvote 0
Texas Longhorn said:
Thanks--the formulas work great. That being said, I used PaddyD's formula, which does exactly what I need, but I have no idea what I told Excel to do (the more I'm here, the more I realize I define amateur). Could someone explain what the formula is doing?

Thanks.

See for SumProduct:

http://216.92.17.166/board2/viewtopic.php?t=59063

In

=SUMPRODUCT((SUBTOTAL(3,OFFSET(A4:A14,ROW(A4:A14)-MIN(ROW(A4:A14)),,1)))*((A4:A14)=E1)*(B4:B14))

the SUBTOTAL bit established which rows are visible (invented by Longre).

The conditional bit...

(A4:A14)=E1

establishes the A-cells that are equal to E1.

Algebraic And'ing of the result of the SubTotal bit, the conditional bit, and the range to sum (B1:B4) gives the desired total.
 
Upvote 0
Aladin, thanks. I enjoyed your sumproduct explanation. I am still lost on the OFFSET part of the formula, particularly the ROW(A4:A14)-MIN(ROW(A4:A14)),,1 part.

Sorry for all the questions.

Thanks.
 
Upvote 0
Texas Longhorn said:
Aladin, thanks. I enjoyed your sumproduct explanation. I am still lost on the OFFSET part of the formula, particularly the ROW(A4:A14)-MIN(ROW(A4:A14)),,1 part.

Sorry for all the questions.

Thanks.

The ROW(A4:A14)-MIN(ROW(A4:A14)) bit, when evaluated (check with F9 on the formula bar), gives:

{0,1,2,3} [ MIN helps to get 0 that is needed in order to include the start cell ]

an array each member of which specifies the number of rows from A1 (A1:A4 is read off by OFFSET as A1). A constant array as a rows specifier in OFFSET makes the formula possible. SUBTOTAL applies COUNTA (3) to a set of single-cell ranges. Since SUBTOTAL ignores invisible cells, we get an array of 1's and 0's (1 for each visible cell, 0 for each invisble cell).
 
Upvote 0
The ROW(A4:A14)-MIN(ROW(A4:A14)) bit, when evaluated (check with F9 on the formula bar), gives:

{0,1,2,3} [ MIN helps to get 0 that is needed in order to include the start cell ]

an array each member of which specifies the number of rows from A1 (A1:A4 is read off by OFFSET as A1). A constant array as a rows specifier in OFFSET makes the formula possible. SUBTOTAL applies COUNTA (3) to a set of single-cell ranges. Since SUBTOTAL ignores invisible cells, we get an array of 1's and 0's (1 for each visible cell, 0 for each invisble cell).

Absolutely phenomenal!! Aladin loved your explanation of the array. Generating a series of 1's and 0's - ingenius!
 
Upvote 0

Forum statistics

Threads
1,216,085
Messages
6,128,733
Members
449,465
Latest member
TAKLAM

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