+ Reply to Thread
Results 1 to 20 of 20

Difference between the SUBTOTAL(103) and COUNTA?

  1. #1
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Difference between the SUBTOTAL(103) and COUNTA?

    Hi all,

    I have a problem. In some cells A1:AD1 are the texts, the rest are empty.

    1. If I mark A2: Z2 and introduce a formula
    Please Login or Register  to view this content.
    completed Ctrl + Shift + Enter in these cells have values ​​0/1

    2. If I mark A3: Z3 and introduce a formula
    Please Login or Register  to view this content.
    completed Ctrl + Shift + Enter in these cells have the same value as in the case of using COUNTA in step 1.

    3. If you have a formula for A4
    Please Login or Register  to view this content.
    in the A4 I have the result of "OK" or "" depends on the content A1:AD1

    4. If you have a formula for A5
    Please Login or Register  to view this content.
    I have it in A5 #N/A (Ecel 2007) or ""

    My question:
    1. Why formula
    Please Login or Register  to view this content.
    It is correct (result = OK) and the formula
    Please Login or Register  to view this content.
    It is no longer correct (result = #N/A or "")?

    After all, and in step 1 and step 2 are returned to the same horizontal arrays.

    2. In this particular case, what feature SUBTOTAL decides that the SUBTOTAL formula is correct?

    Sorry, I do not know English

    Thank you.

    Tomek
    Attached Files Attached Files

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    COUNTA counts the number of cells in a range that are not empty and returns that number. SUBTOTAL gives a "total" of the cells in a range that have a numeric value, including 0 then dividing that number by the number of cells in the range that contain a numeric value.

    Edit* If this didn't help you at all, my apologies, there is a very good chance I misunderstood what you were asking.
    Last edited by gmr4evr1; 05-31-2015 at 02:23 PM.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    Thank you, gmr4evr1.

    It's about SUBTOTAL(103) does not SUBTOTAL(102)
    In addition, the results of A2:Z2 and A3:Z3 are correct. Why the formulas in A4 is correct and in A5 - incorrect

  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: Difference between the SUBTOTAL(103) and COUNTA?

    The SUBTOTAL function is generally used on filtered data.

    The 100 series index numbers will ignore data that is hidden either by filtering or by other means of hiding rows.

    The 1-11 series index numbers will only ignore data hidden by filtering.

    The COUNTA function will count both hidden and visible cells.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    Tony Valko, I know how it works SUBTOTAL and COUNTA. In my case, there are no hidden cells.
    Question: Why formula
    Please Login or Register  to view this content.
    It is correct and the formula
    Please Login or Register  to view this content.
    It is no longer correct?
    since
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    They return the same array 26 elements

  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: Difference between the SUBTOTAL(103) and COUNTA?

    It's because the SUBTOTAL function can handle an array of offsets but the COUNTA function can't.

    Use a smaller range of cells (it will be easier to follow what's going to happen) then select the formula cell. Goto the Formulas tab>Evaluate Formula. Repeatedly click the Evaluate button and it will step through the formula showing you what results each expression in the formula generates. This is a great tool for learning how formulas work.

    Here's another way to write the formula that doesn't use the volatile OFFSET function.

    Array entered**:

    =IF(SUM(IF(FREQUENCY(IF(A1:AD1<>"",COLUMN(A1:AD1)),IF(A1:AD1="",COLUMN(A1:AD1)))=5,1))=1,"OK","")

    ** 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.

  7. #7
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    "It's because the SUBTOTAL function can handle an array of offsets but the COUNTA function can't."

    {=--(COUNTA(OFFSET($A$1;;COLUMN($A:$Z)-1;;5))=5)} (A2:Z2)
    and
    =--(SUBTOTAL(103;OFFSET($A$1;;COLUMN($A:$Z)-1;;5))=5) (A3:Z3)
    They work very well

    =IF(SUMPRODUCT(--(SUBTOTAL(103;OFFSET($A$1;;COLUMN($A:$Z)-1;;5))=5))=1;"OK";"")
    also it works very well.

    "Here's another way to write the formula that doesn't use the volatile OFFSET function"

    I know how to replace OFFSET another function. A and OFFSET (... SUBTOTAL (103, OFFSET ...) formula also works. So I've got a formula. I'm just curious as to why the site SUBTOTAL (103), use COUNTA it no longer works.
    Last edited by hungt; 06-01-2015 at 08:07 AM.

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    Quote Originally Posted by hungt View Post
    I'm just curious as to why the site SUBTOTAL (103), use COUNTA it no longer works.
    Quote Originally Posted by Tony Valko View Post
    It's because the SUBTOTAL function can handle an array of offsets but the COUNTA function can't.
    With this
    =IF(SUMPRODUCT(--(SUBTOTAL(103;OFFSET($A$1;;COLUMN($A:$Z)-1;;5))=5))=1;"OK";"")
    Sumproduct is summing an 'array of results' created by the Subtotal/Offset.
    1 for each element of Column($A:$Z), so 26 results.
    It would calculate something like this
    =IF(SUMPRODUCT(--(SUBTOTAL(103;OFFSET($A$1;;COLUMN($A:$Z)-1;;5))=5))=1;"OK";"")
    =IF(SUMPRODUCT(--(SUBTOTAL(103;OFFSET($A$1;;{1,2,3,4,5,etc,26}-1;;5))=5))=1;"OK";"")
    =IF(SUMPRODUCT(--(SUBTOTAL(103;OFFSET($A$1;;{0,1,2,3,4,etc,25};;5))=5))=1;"OK";"")
    =IF(SUMPRODUCT(--(SUBTOTAL(103;{A$1:$A$5,$B$1:$B$5,$C$1:$C$5,$D$1:$D$5,$E$1:$E$5,etc,$Z$1:$Z$5})=5))=1;"OK";"")
    =IF(SUMPRODUCT(--({2,5,3,4,0,etc,5}=5))=1;"OK";"") <- I just threw in random numbers as the results of the subtotal functions.

    COUNTA can't work with that array of results like subtotal can.
    It can only create a single result.
    Last edited by Jonmo1; 06-01-2015 at 08:48 AM.

  9. #9
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    "... for each element of Column($A:$Z), so 26 results ..."
    I know how 'array of results' is created. That's not what I'm asking
    "COUNTA can't work with that array of results like subtotal can.
    It can only create a single result
    ."
    This is not true. COUNTA also can create an 'array of results'.
    --SUBTOTAL (...) Creates such a 'array of results'
    --COUNTA(...) Also creates such a 'array of results' - see A2:Z2 in file Book1.xlsx

    For now I know that the 'array of results' returned by SUBTOTAL may be an argument for SUMPRODUCT (SUM) and the 'array of results' returned by COUNTA can not be an argument for SUMPRODUCT (SUM). Just do not know why

  10. #10
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    "... for each element of Column($A:$Z), so 26 results ..."
    I know how 'array of results' is created. That's not what I'm asking
    "COUNTA can't work with that array of results like subtotal can.
    It can only create a single result
    ."
    This is not true. COUNTA also can create an 'array of results'.
    --SUBTOTAL (...) Creates such a 'array of results'
    --COUNTA(...) Also creates such a 'array of results' - see A2:Z2 in file Book1.xlsx

    For now I know that the 'array of results' returned by SUBTOTAL may be an argument for SUMPRODUCT (SUM) and the 'array of results' returned by COUNTA can not be an argument for SUMPRODUCT (SUM). Just do not know why

  11. #11
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    Quote Originally Posted by hungt View Post
    This is not true. COUNTA also can create an 'array of results'.
    That may be true, but that's not the point.

    It's not that counta can't 'create' an array of results.
    It's that Counta cannot USE the array of ranges created by the offset.

    In that formula, it's OFFSET that is 'creating' the array of ranges.


    In the example I wrote up in previous post
    When it gets to this point
    =IF(SUMPRODUCT(--(SUBTOTAL(103;{A$1:$A$5,$B$1:$B$5,$C$1:$C$5,$D$1:$D$5,$E$1:$E$5,etc,$Z$1:$Z$5})=5))=1;"OK";"")
    It's the OFFSET function that 'created' that array of ranges, not subtotal, or counta.

    Subtotal can then USE that array of ranges, Counta cannot.
    Counta would consider that one big range, A1:Z5
    As if you wrote COUNTA(A1:A5, B1:B5, C1:C5)

    Subtotal is able to use each element in that array of ranges, so you get
    {SUBTOTAL(103,A1:A5), SUBTOTAL(103,B1:B5), SUBTOTAL(103,C1:C5)}

  12. #12
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    It's that Counta cannot USE the array of ranges created by the offset
    ...
    Subtotal can then USE that array of ranges, Counta cannot


    You looked at A2:Z2? You can see that COUNTA also can use that array of ranges created by the offset

  13. #13
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    Yes I did, and counta does NOT use an array of ranges..

    In A2:Z2, each formula evaluates only 1 range.

    In A2, it's evaluateing A1:A5
    In B2, it's evaluateing B1:B5
    In C2, it's evaluateing C1:C5
    etc..

  14. #14
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    And sorry, i've been reading the offset wrong, it's 5 columns not rows.
    so A1:E1 then B1:F1 then C1:G1 etc..

  15. #15
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    Quote Originally Posted by Jonmo1 View Post
    Yes I did, and counta does NOT use an array of ranges..
    For sure COUNTA use an array of ranges
    You compare A2:Z2 and A3:Z3? Always A2:Z2 = A3:Z3
    In A2:Z2, each formula evaluates only 1 range.

    In A2, it's evaluateing A1:E1
    In B2, it's evaluateing B1:F1
    In C2, it's evaluateing C1:G1
    etc..
    Just as SUBTOTAL
    In A3:Z3, each formula evaluates only 1 range.
    In A3, it's A1:E1
    In B3, it's B1:F1
    In C3, it's C1:G1
    etc..
    in Z3, it's Z1:AD1
    Last edited by hungt; 06-01-2015 at 03:46 PM.

  16. #16
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    The question isn't why subtotal DOES work in A3:Z3, or counta does work in A2:Z2.
    It's why counta Doesn't work in this 'single' formula
    =IF(SUMPRODUCT(--(COUNTA(OFFSET($A$1;;COLUMN($A:$Z)-1;;5))=5))=1;"OK";"")
    Right?

    In A2:Z2, you put in this array of formula
    =--(COUNTA(OFFSET($A$1;;COLUMN($A:$Z)-1;;5))=5)
    Here's how that gets processed when you press CTRL + SHIFT + ENTER
    A2: =--(COUNTA(OFFSET($A$1;;COLUMN($A:$A)-1;;5))=5) Then =--(COUNTA(OFFSET($A$1;;1-1;;5))=5)
    B2: =--(COUNTA(OFFSET($A$1;;COLUMN($B:$B)-1;;5))=5) Then =--(COUNTA(OFFSET($A$1;;2-1;;5))=5)
    C2: =--(COUNTA(OFFSET($A$1;;COLUMN($C:$C)-1;;5))=5) Then =--(COUNTA(OFFSET($A$1;;3-1;;5))=5)
    etc..
    Then offset get's to it
    A2: =--(COUNTA($A$1:$E$1)=5)
    B2: =--(COUNTA($B$1:$F$1)=5)
    C2: =--(COUNTA($C$1:$G$1)=5)

    COUNTA never even looks at an array of ranges.


    Do you see how that process is different from how the single formula in A5 calculates as I described in my first post #8 ?

  17. #17
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    Quote Originally Posted by Jonmo1 View Post
    Do you see how that process is different from how the single formula in A5 calculates as I described in my first post #8 ?
    So the result returned by SUBTOTAL (...) is treated as an array of 26 values and the result returned by the COUNTA (...) is treated as 26 single values?
    If so this is exactly what I mean

    Thank you very much for your time and efforts loaded

  18. #18
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    Almost, but quite.

    The 'meat' of the issue is happening before subtotal or counta even come into play.
    It's OFFSET with the use of COLUMN(A:Z) that is 'creating' the array of ranges. like
    {A$1:$E$1,$B$1:$F$1,$C$1:$G$1,$D$1:$H$1,$E$1:$I$1,etc,$Z$1:$AD$1}

    Subtotal can process that the way you want, to get an array of 26 different results of the subtotal, 1 for A1:E1, 1 for B1:F1, 1 for C1:G1 etc..
    Counta cannot do that.

    Counta would see that like
    =COUNTA(A1:E1,B1:F1,C1:G1)

    Just to see, go ahead and put that exact formula in a cell, and put values in A1:G1 and see what happens.
    Even if you entered it with CTRL + SHIFT + ENTER
    It's not doing what you think it does.

  19. #19
    Registered User
    Join Date
    05-02-2013
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    Quote Originally Posted by Jonmo1 View Post
    Counta would see that like
    =COUNTA(A1:E1,B1:F1,C1:G1)

    Just to see, go ahead and put that exact formula in a cell, and put values in A1:G1 and see what happens.
    Even if you entered it with CTRL + SHIFT + ENTER
    It's not doing what you think it does.
    I understand. Once again, thank you very much.

  20. #20
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Difference between the SUBTOTAL(103) and COUNTA?

    You're welcome.

+ 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. Display percent difference for subtotal only.
    By brent_milne in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 02-27-2015, 12:28 PM
  2. Replies: 1
    Last Post: 09-18-2013, 04:10 PM
  3. SUBTOTAL and COUNTA
    By hungt in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-02-2013, 08:43 PM
  4. Replies: 8
    Last Post: 07-31-2012, 09:41 AM
  5. 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

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