Dec 16 2020 11:31 PM - edited Dec 16 2020 11:34 PM
I am trying to do a subtotal of the number with multiple criteria.
E.g. with the sample data below, there will be filters applied to the table, say date filters.
I am looking for the Subtotal of Color = "Red", Fruit = "Apple", where I should get the answer 18.
Any idea how I can achieve this?
Date | Color | Fruit | Number |
1/1/2020 | Red | Apple | 7 |
1/2/2020 | Red | Watermelon | 10 |
1/3/2020 | Red | Apple | 2 |
1/4/2020 | Green | Pear | 8 |
1/5/2020 | Yellow | Mango | 4 |
1/6/2020 | Red | Watermelon | 3 |
1/7/2020 | Red | Apple | 9 |
1/8/2020 | Green | Apple | 1 |
1/9/2020 | Green | Pear | 3 |
1/10/2020 | Red | Watermelon | 4 |
1/11/2020 | Yellow | Mango | 2 |
1/12/2020 | Green | Apple | 3 |
Dec 17 2020 02:59 AM
Depends on what you'd like to achieve. If you add Total row to the table and would like to sum here
Excel on AutoSum automatically adds proper formula which sums only filtered values.
If you'd like to sum outside the table, here are two options - would you like to sum filtered values only or all of them independently of filtering. In first case helper column will be needed, and in both cases SUMIFS() works.
Dec 20 2020 11:13 PM
Hi @Sergei Baklan thank you for your example. I would like to sum outside the table, and to sum filtered values only. However, I am not too sure how to integrate SUMIFS() with SUBTOTAL() function. How could I do that?
Say for example, on another page, I have table headers for different fruits. When I adjust the slicer, I would like for the row below to calculate the sum of each category basis the filters used.
Dec 22 2020 12:46 PM
SolutionIf so you need to add the helper column to the table like
=AGGREGATE(3,5,[@Color])
which indicates if current row is filtered or not.
With that formula in L2 is
=SUMIFS(Table1[[Number]:[Number]], Table1[[Fruit]:[Fruit]],L$1, Table1[[Helper]:[Helper]],1)
and drag it to the right.
If exclude Fruit filter the rest sum could be received by reference on table total
Dec 22 2020 06:04 PM
@Sergei Baklan huge thanks! I've been looking for this exact solution. Have a merry Christmas and new year.
Dec 23 2020 01:26 AM
Thank you and Happy Holidays!
Dec 22 2020 12:46 PM
SolutionIf so you need to add the helper column to the table like
=AGGREGATE(3,5,[@Color])
which indicates if current row is filtered or not.
With that formula in L2 is
=SUMIFS(Table1[[Number]:[Number]], Table1[[Fruit]:[Fruit]],L$1, Table1[[Helper]:[Helper]],1)
and drag it to the right.
If exclude Fruit filter the rest sum could be received by reference on table total