0

I currently use a SUBTOTAL function in Excel 365 to either sum, count or average a bunch of cells in a range. I was previously manually filtering the range so I was only totaling the rows I wanted, however the need has arisen to be able to look at several criteria at once. i.e. in the example below, I was previously manually filtering range to only include "Apple" but now I need to be able to total "Apple", "Orange", "Banana" separately, at the same time.

The subtotal fields are used in graphs and I have a cell (F5) that houses a number corresponding to either SUM, COUNT or AVERAGE (9, 2 or 1) to use in the SUBTOTAL formulas in the "Summary table" which is linked to other functionality within the workbook and I need to still be able to retain that functionality.

Example of how my sheet is setup:

Raw Data

Product Type Sales QTY Date
Apple 4 1/9/21
Orange 3 6/9/21
Banana 2 10/9/21
Apple 6 14/9/21
Orange 6 20/9/21
Apple 5 29/9/21

The criteria I want to match is in Column 1 (Product Type) of the summary table.

Basically, I then want to be able to end up with the ability to display the data either as totals:

$F$5 = 9

for each line: SUBTOTAL($F$5,SalesQTY)

Summary table

Product Type Result (Sales Per Month)
Apple 15
Orange 9
Banana 2

Or as averages:

$F$5 = 1

for each line: SUBTOTAL($F$5,SalesQTY)

Product Type Result (Average QTY per Sale)
Apple 5
Orange 4.5
Banana 2

Or as a count:

$F$5 = 2

for each line: SUBTOTAL($F$5,SalesQTY)

Product Type Result (# Sales Transactions)
Apple 2
Orange 2
Banana 1

Is there some way I can combine SUMIF and also SUBTOTAL but also be able to retain the ability to flick between average, sum and count?

I have found a few questions and answers where SUMIF or SUMPRODUCT is used in place of SUBTOTAL, but I can't work out how to use those and still be able to flick between AVERAGE, SUM and COUNT.

2 Answers 2

0

Create a nested if: if ($F$5 = 1, use AVERAGEIF, if ($F$5 = 2, use COUNTIF,( if $F$5 = 9, use SUMIF, "")))

1
  • Thanks, I ended up doing this. Commented Sep 30, 2021 at 23:24
0

Not sure if creating a pivot table can help you: Select the table, and then go to Insert tab>PivotTable>click OK.
Please check the test screen recording. : enter image description here

1
  • Hi, sorry I should have mentioned, the data is already in a pivot table. But due to the nature of the graphs, I need all the answers in just one column. The file is kind of a dashboard. So the graph data changes to reflect different things based on selections made. I can use another table for each that displays data based on an index, I was just trying to avoid the rework. Commented Sep 30, 2021 at 23:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .