+ Reply to Thread
Results 1 to 18 of 18

Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

  1. #1
    Registered User
    Join Date
    09-26-2014
    Location
    Houston,TX
    MS-Off Ver
    Excel 2010
    Posts
    19

    Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Hello,

    I am attempting to add a formula to my spreadsheet that will calculate the count of unique numbers in a column when I use multiple filters (while avoiding counting the duplicates.) I have browsed multiple threads on this topic, but so far no solution has worked for me. I am hoping someone can help me solve this. My number range starts in cell P12 and goes through P44 as of now, however I would like to extend that range to P1048576 if possible.

    I have tried this example from another thread and it failed to yield the desired solution... (Yielded a Value error)

    =SUM(IF(FREQUENCY(IF(SUBTOTAL(3,OFFSET(P12,ROW(P12:P44)-ROW(P12),0)),MATCH(P12:P44,P12:P44,0)),ROW(P12:P44)-ROW(P12)+1),1))

    Any help would be appreciated!

    Thanks

  2. #2
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    I've never used that long formula, but you could try this formula:

    =SUM(IF(FREQUENCY(P12:P44,P12:P44)>0,1))

    (On a side note - I have a feeling that you may be getting the #VAL error because you didn't hit Ctrl + Shift + Enter)

    To change the formula to go to P1048576, just use that instead of P44.

    - Moo
    Last edited by Moo the Dog; 09-26-2014 at 05:32 PM.

  3. #3
    Registered User
    Join Date
    09-26-2014
    Location
    Houston,TX
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Thanks for the reply! The formula worked for me, however when I go to filter it does not recalculate based on what I have filtered on. Do you know how to alter the formula to account for this? Based on some things I have read, the Subtotal function should be involved.

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Try this array formula**:

    =SUM(IF(FREQUENCY(IF(SUBTOTAL(2,OFFSET(P12,ROW(P12:P44)-ROW(P12),0)),P12:P44),P12:P44),1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Registered User
    Join Date
    09-26-2014
    Location
    Houston,TX
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Thanks for your reply Tony!

    The formula is calculating correctly when no filters are on, however when I go to add filters, it is calculating the wrong # for me. For instance, it was showing 4 when it should have showed 8 and 22 when it should have shown 12. Any other suggestion I could try? Again, I am looking for a Subtotal when filtered that display the count of a column while avoiding duplicate entries. I appreciate the help!!

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Here's a small sample file created in Excel 2010 that demonstrates this.
    Attached Files Attached Files

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Quote Originally Posted by swoosh1014 View Post
    My number range starts in cell P12 and goes through P44 as of now, however I would like to extend that range to P1048576 if possible.
    I just noticed that.

    Instead of using that huge range of mostly empty cells I think you should use a dynamic range.

    Let's get the formula working then we'll apply the dynamic range.

  8. #8
    Registered User
    Join Date
    09-26-2014
    Location
    Houston,TX
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Ok perfect!! The formula seems to be working now... I know I entered it as an array but it looks like it didn't take or somehow reverted back.

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Good deal!

    OK, define the dynamic range...

    Goto the Formulas tab>Define Name
    Name: Range (or whatever name you want to use)
    Refers to:

    =Sheet1!$P$12:INDEX(Sheet1!$P:$P,MATCH(1E+100,Sheet1!$P:$P))

    Use the appropriate sheet name.

    Then, the formula becomes:

    =SUM(IF(FREQUENCY(IF(SUBTOTAL(2,OFFSET(INDEX(Range,1),ROW(Range)-MIN(ROW(Range)),0)),Range),Range),1))

    Still array entered.

  10. #10
    Registered User
    Join Date
    09-26-2014
    Location
    Houston,TX
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Problem solved!! Thanks again for the help Tony, you were of great assistance!!

  11. #11
    Registered User
    Join Date
    09-26-2014
    Location
    Houston,TX
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Actually Tony, I have 1 more question if you dont mind... Is there a way to adjust this formula so that it doesnt add to the count if I have a blank value in the corresponding row, but in column O?

    This is my formula as of now:

    =SUM(IF(FREQUENCY(IF(SUBTOTAL(2,OFFSET(P12,ROW(P12:P1048576)-ROW(P12),0)),P12:P1048576),P12:P1048576),1))

    However, if O 15 is blank, I dont want P15 to count towards the subtotal in the above formula. Does that make sense?

    Thanks!

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Maybe this...

    =SUM(IF(FREQUENCY(IF(SUBTOTAL(2,OFFSET(P12,ROW(P12:P30)-ROW(P12),0)),IF(O12:O30<>"",P12:P30)),P12:P30),1))

    However, that will still count numbers if not all of the corresponding cells for a particular number in column O are empty. For example:

    Data Range
    O
    P
    11
    Data
    Value
    12
    x
    1
    13
    1
    14
    2
    15
    2
    16
    3
    17
    4
    18
    5
    19
    5
    20
    5
    21
    6


    The formula result = 1. The 1st 1 in cell P12 is being counted.

  13. #13
    Registered User
    Join Date
    09-26-2014
    Location
    Houston,TX
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Hey Tony,

    I entered the array as follows: =SUM(IF(FREQUENCY(IF(SUBTOTAL(2,OFFSET(P12,ROW(P12:P86)-ROW(P12),0)),IF(O12:O86<>"",P12:P86)),P12:P86),1)) and am receiving a #value! error.

    Does this look right to you, and if not, any other suggestions that I could try?

    Thanks again!

  14. #14
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Did you enter it as an array formula?

    Array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

  15. #15
    Registered User
    Join Date
    09-26-2014
    Location
    Houston,TX
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Yep that was it, thought I had done it previously but I guess not. Got it working now:

    =SUM(IF(FREQUENCY(IF(SUBTOTAL(2,OFFSET(P12,ROW(P12:P1048576)-ROW(P12),0)),IF(O12:O1048576<>"",P12:P1048576)),P12:P1048576),1))

    I am sorry to do this to you, but I still need a little more help... I am still new to excel and can't manipulate the formuals the way I would like to yet...

    It looks like my formula is still counting results in Column O that are negative number values.

    For example:

    Column O Column P
    150 7
    -36 15
    21
    50 24

    So in this instance, I would like my formula to exclude the -36 , in addition to the blanks from column O that it is already including, and give me a result of 2.

    I think once we get this part figured out, everything should be perfect!!

    Thanks again so much!

  16. #16
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Sorry for the delayed response, I took a few weeks off!

    Can you post a SMALL sample file and show me what results you expect?

    About 20-30 rows and 3 or 4 columns worth of data is plenty.

  17. #17
    Registered User
    Join Date
    09-26-2014
    Location
    Houston,TX
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Not a problem Tony, I have done the same. In the meantime I had this issue solved and will mark it as such. Again, I appreciate all the help you provided in this thread.

  18. #18
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to Calculate Subtotal - Count of #'s Column While Avoiding Duplicates

    Good deal. Thanks for the feedback!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Subtotal - Delete zero Subtotal and prior rows that calculate to that zero Subtotal
    By Whatsherface in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2012, 08:37 PM
  2. Replies: 3
    Last Post: 01-22-2010, 10:08 AM
  3. AutoFilter - Avoiding Duplicates
    By spud2486 in forum Excel General
    Replies: 1
    Last Post: 10-17-2008, 02:53 PM
  4. Avoiding Duplicates
    By Mald in forum Excel General
    Replies: 4
    Last Post: 08-01-2006, 10:40 AM
  5. [SOLVED] Count unique values among duplicates in a subtotal range
    By jcpotwor in forum Excel General
    Replies: 2
    Last Post: 01-12-2006, 09:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1