+ Reply to Thread
Results 1 to 18 of 18

SUM array works, COUNT array does not?

Hybrid View

  1. #1
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    SUM array works, COUNT array does not?

    In an array like this...
    A
    B
    C
    2
    1
    2
    4
    3
    2
    4
    8
    4
    3
    6
    12
    5
    4
    8
    16
    6
    5
    10
    20


    I am trying to sum and count numbers in every 2nd row.

    I am using these ARRAY's...
    =SUM(IF(MOD(A1:A6,2)=1,A1:C6,0))
    works fine, gives 63

    and then...
    =COUNT(IF(MOD(A1:A6,2)=1,A1:C6,0))
    doesnt work, gives 18

    What gives, what am I missing?

    Edit: It seems that it is doubling the count...6 rows using every 2nd row = 3 rows with 3 values in each = 9 numbers, not 18
    Last edited by FDibbins; 10-10-2014 at 08:41 PM.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,412

    Re: SUM array works, COUNT array does not?

    You are telling it to count a zero on even rows - try it this way:

    =COUNT(IF(MOD(ROW(A1:C6),2)=1,A1:C6))

    (CSE-entered). Note: count nothing if even.

    Hope this helps.

    Pete

  3. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: SUM array works, COUNT array does not?

    Why using = 1...
    I believe there is no need...
    For Sum
    Formula: copy to clipboard
    =SUM(IF(MOD(A1:A5,2),A1:C5))

    For Count
    Formula: copy to clipboard
    =COUNT(IF(MOD(ROW(A1:C5),2),A1:C5))
    Last edited by Vikas_Gautam; 10-10-2014 at 11:41 PM.
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: SUM array works, COUNT array does not?

    @ Vikas, yes, that works for this situation there are only 2 options - 0 or 1

    and now Im even more confused (maybe coz its late here, 20 past midnite), but deleting ALL values does not change the answers...
    A
    B
    C
    D
    E
    1
    9
    =COUNT(IF(MOD(ROW(A1:A6),2)=1,A1:C6))
    2
    1
    2
    4
    9
    =COUNT(IF(MOD(ROW(A1:A6),2)=1,A1:C6))
    3
    2
    4
    8
    9
    =COUNT(IF(MOD(ROW(A1:C5),2),A1:C5))
    4
    3
    6
    12
    5
    4
    8
    16
    6
    5
    10
    20


    and...
    A
    B
    C
    D
    E
    1
    9
    =COUNT(IF(MOD(ROW(A1:A6),2)=1,A1:C6))
    2
    9
    =COUNT(IF(MOD(ROW(A1:A6),2)=1,A1:C6))
    3
    9
    =COUNT(IF(MOD(ROW(A1:C5),2),A1:C5))
    4
    5
    6

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: SUM array works, COUNT array does not?

    I think to count numbers as per the criteria, the following Array Formula can be used...

    =SUM(IF(MOD(A1:A6,2)=1,--ISNUMBER(A1:C6)))
    Or this non-array formula......

    =SUMPRODUCT(--(MOD(A1:A6,2)=1)*--(ISNUMBER(A1:C6)))
    Last edited by sktneer; 10-11-2014 at 01:34 AM.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,038

    Re: SUM array works, COUNT array does not?

    sktneer,
    no need to convert TRUE/FALSE to 1/0 with -- AND to multiply.

    It's enough to have:
    Formula: copy to clipboard
    =SUMPRODUCT((MOD(A1:A6,2)=1)*(ISNUMBER(A1:C6)))


    Any math operation will convert TRUE/FALSE into numbers (including *)
    Last edited by zbor; 10-11-2014 at 01:43 AM.
    Never use Merged Cells in Excel

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,038

    Re: SUM array works, COUNT array does not?

    FD,
    work for me.
    Attached Files Attached Files

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: SUM array works, COUNT array does not?

    @zbor
    You are correct. No need to use double negative in this case.
    And You already suggested the formula in post#7 what I suggested in post#8. Didn't see it.

  9. #9
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: SUM array works, COUNT array does not?

    I think 0 in the false condition is producing the error.

    You formula could be like this.....
    =COUNT(IF(MOD(A1:A6,2)=1,A1:C6,""))
    Or just leave the false condition,

    =COUNT(IF(MOD(A1:A6,2)=1,A1:C6))

  10. #10
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,038

    Re: SUM array works, COUNT array does not?

    I've just use FDibbins's formulae as they are.
    I didn't change them and I got correct result.

    @FDibbins, check did you accidently use manual calculation in workbook.

  11. #11
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: SUM array works, COUNT array does not?

    No Sir. The formula you used is different from one which Ford used originally. You removed the 0 from the formula as a false condition while Ford used 0 in his formula (Post#1). Count() will treat 0 a a number.

  12. #12
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,038

    Re: SUM array works, COUNT array does not?

    I'm talking about FD formulae in #4, not #1.

  13. #13
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: SUM array works, COUNT array does not?

    Oh yes. He also used the same formula in post#4. In this case what you suggested about the manual calculation might be the reason behind the wrong output.

  14. #14
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: SUM array works, COUNT array does not?

    This will work for counting values in every odd row.

    Formula: copy to clipboard
    =SUMPRODUCT(NOT(ISBLANK(A1:C6))* ISODD(ROW(A1:C6)))
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  15. #15
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Cool Re: SUM array works, COUNT array does not?

    I think it should be..
    Count:-
    Formula: copy to clipboard
    =SUMPRODUCT(MOD(ROW(A1:A6),2)*(ISNUMBER(A1:C6)))

    Sum:-
    Formula: copy to clipboard
    =SUMPRODUCT(MOD(ROW(A1:A6),2)*(ISNUMBER(A1:C6)),A1:C6)

    Check the attached file..
    Attached Files Attached Files
    Last edited by Vikas_Gautam; 10-11-2014 at 02:16 PM.

  16. #16
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: SUM array works, COUNT array does not?

    Only have a few minutes, but no, calcs were not set to manual. I will look again in an hour or so, thanks for all the inputs guys

  17. #17
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,699

    Re: SUM array works, COUNT array does not?

    I think there are 2 separate issues that have arisen:

    Firstly when you use this version

    =COUNT(IF(MOD(ROW(A1:C6),2)=1,A1:C6,0))

    You get 18 because you have zero as the FALSE argument, and COUNT counts those zeroes.......but suggested fix, i.e.

    =COUNT(IF(MOD(ROW(A1:C6),2)=1,A1:C6))

    will still count blanks in A1:C6 as zeroes and so COUNT counts those too, giving 9 even if A1:C6 is completely blank

    To me there is also a "robustness" issue using ROW(A1:C6) in that you will get different results if you insert a row at row 1 - for that reason my suggested solution is this:

    =SUMPRODUCT(ISNUMBER(A1:C6)*(MOD(ROW(A1:C6)-ROW(A1),2)=1))

    That would fix all the issues with a robust non array formula
    Audere est facere

  18. #18
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: SUM array works, COUNT array does not?

    DDL thanks for that, it was driving me nuts

+ 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. Array Formula only works if entered in more than one cell
    By Speshul in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-08-2014, 02:18 PM
  2. [SOLVED] Quick Array question - Copy array to another array then resize?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-02-2013, 01:17 AM
  3. [SOLVED] Create 1-col array identifying occurrence count in a 1-col array
    By empsall in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-26-2013, 12:50 PM
  4. [SOLVED] Count multiple conditions array only works with 1 value
    By bob33 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-19-2013, 12:57 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