Subtotal on a countif - calculating a % of a condition

Johnnyboy1x

New Member
Joined
Jan 11, 2013
Messages
32
Hello All --

I have been struggling with this. I want to be able to filter and return a result for a percent of cells that meet a condition. In my case -30 ---> +30 are green results and I am calculating the percentage of green from the whole total.

I tried to accomplish this using multiple subtotal formulas, from which the results would then calculate the percentage.

It works in theory, and when not filtering, but not when filtering. I can't get the countif statements right for the first formula.


DATA SET EXAMPLE --

statusserialtypedays from target
Closed136761/13 PM-35
Closed128083/09PM-31
Closed141305/15PM-3
Closed123013/07PM-1
Closed137902/14INST-1
Closed133326/11INST32
Closed125949/08INST33
Closed141734/15PM34

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>


FIRST FORMULA -- (where I am having the problem)

'=SUM(COUNTIF(D:D,">30")+(COUNTIF(D:D,"<-30"))) --- This works as it should and returns a result of 5 for the above data set. But, when I filter out the result doesn't change (as it shouldn't.

So I tried to do this (next formula below), but no matter what i do I can't get excel to like it...ask for missing parenthesis or arguments and no matter what I do its not happy. '=SUBTOTAL(109,(COUNTIF(D:D,">30")+(COUNTIF(D:D,"<-30")))

SECOND FORMULA --

'=SUBTOTAL(2,D:D). This works as it should and returns a count of 8 for the above data set and changes when filtering. GREAT!

THIRD FORMULA --

Cell formated as a percent and I calculate the percentage of the above 2 results with the formula below. Returns 38% as it should.

'=(F2-E2)/F2


HOW CAN I ACHIEVE THE SUBTOTALS FOR THE COUNT IF IN THE FIRST FORMULA OR DO I NEED A COMPLETELY DIFFERENT APPROACH.

Thanks, Johnnyboy1x
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
To keep the formulas relatively simple it would be easier to use a helper column, in E2 use this formula copied down

=SUBTOTAL(2,E2)

Then for a count that only considers visible values

=SUM(COUNTIFS(E:E,1,D:D,{">30","<-30"}))

You can hide column E if you want
 
Last edited:
Upvote 0
Thank you for the quick reply Barry.

It is close but filtering still seems not to work.

Does this all seem right to you? I started my formulas in F1 so they are not in the data set. I changed the header of E to a number and everycell in E =SUBTOTAL(2,E1),

What am I missing?

statusserialtypedays from target12345
Closed123013/07PM11
Closed128083/09PM351
Closed136761/13PM351
Closed141305/15PM351
Closed137902/14INST11
Closed133326/11INST11
Closed125949/08INST331
Closed141734/15PM-341
Closed141734/15PM51
Closed141734/15PM51

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>

sum count ifcountpercent on time
51050%
=SUM(COUNTIFS(E:E,1,D:D,{">30","<-30"}))=SUBTOTAL(2,D:D)=(G2-F2)/G2

<colgroup><col><col><col></colgroup><tbody>
</tbody>


Thanks, Johnnyboy1x
 
Upvote 0
Hello Barry -- I got this to work but is cumbersome. Thanks for the support.

1.
sum product >30

=SUMPRODUCT(SUBTOTAL(3,OFFSET(D2:D1000,ROW(D2:D1000)-MIN(ROW(D2:D1000)),,1))*(D2:D1000>30))

2.
sum product <-30
=SUMPRODUCT(SUBTOTAL(3,OFFSET(D2:D1000,ROW(D2:D1000)-MIN(ROW(D2:D1000)),,1))*(D2:D1000<-30))

3.
sum of G and H
=SUM(G2:H2)

4.
visible count of D
=SUBTOTAL(2,D:D)

5.
percent on time
=(J2-I2)/J2



Thanks, John

<colgroup><col></colgroup><tbody>
</tbody>

<colgroup><col></colgroup><tbody>
</tbody>


<colgroup><col></colgroup><tbody>
</tbody>

<colgroup><col></colgroup><tbody>
</tbody>




<colgroup><col></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,537
Members
449,088
Latest member
RandomExceller01

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