+ Reply to Thread
Results 1 to 18 of 18

How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

  1. #1
    Registered User
    Join Date
    09-25-2009
    Location
    London, England
    MS-Off Ver
    MS Office 365
    Posts
    17

    Question How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    Hi all,

    I have the following formula:

    =SUMPRODUCT(($B4:$R4)*(1/$B3:$R3)*($B$1:$R$1=$B$8))/COUNTIFS($B$1:$R$1,$B$8)

    ..where:

    - Row 1 is a date range, and I only want cells from rows 3 and 4 to be included if a date condition is met
    - Rows 3 and 4 are data, with row 4 being divided by row 3 when that date condition is met
    - Cell B8 is where I input the date condition value

    - Finally, the COUNTIFS at the end produces an average

    However, my data rows 3 and 4 will sometimes contain #N/A values. I need things that way as I'm producing graphs from the data too and don't want the data points to show up there. The problem is that these cells also stop the formula from working on cells where data is present.

    The first tab shows this working. The second shows it when it doesn't.

    Can you help me add a condition where it will only count cells greater than zero? If a column in row 3 has an #N/A then so should the column in row 4, meaning that the error checking should only be needed once.

    Thanks in advance as always for your expertise!

    SUMPRODUCT Question.xlsx
    Last edited by schnide; 03-27-2024 at 09:22 AM.

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    Hi there.

    A picture is worth 1,000 words. An Excel sheet is worth 1,000 non-editable pictures.

    Please read the yellow banner about sample worksheets, at the top of the screen. Act on its guidelines and post a SMALL sample sheet complete with an explanation and some expected results.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    1. Are you still using Excel 2007? If not, please update your profile.

    2. In the absence of a sheet to play with... one wild guess.

    =SUMPRODUCT((IFERROR($A3:$Z3,0))*(IFERROR(1/$A2:$Z2,0))*($A$1:$Z$1=$A$10))/COUNTIFS($A$1:$Z$1,$A$10)

    If still using Excel 2007 (or anything pre-O365), this will need to be set with CTRL-SHIFT-ENTER instead of enter, before dragging.

  4. #4
    Registered User
    Join Date
    09-25-2009
    Location
    London, England
    MS-Off Ver
    MS Office 365
    Posts
    17

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    All great points you've made Glenn and I've updated everything as you've suggested. This was purely an oversight on my part.

    Not only have I added a sheet but I've also included two separate tabs showing the formula working (without NAs) and not (obviously, with them).

    This does mean the references have changed since I first made the post, which means the example formulas you kindly gave no longer apply. I apologise in advance for any inconvenience.

    At present it doesn't look like that solution in your second post works but I'd absolutely welcome any further input. I'm an experienced Excel user but SUMPRODUCT has always mystified me with its versatility.

  5. #5
    Registered User
    Join Date
    09-25-2009
    Location
    London, England
    MS-Off Ver
    MS Office 365
    Posts
    17

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    If it helps, the correct output in the second tab should be 24.5803223741788.

    I think what your (kindly provided) solution does is treat the column calculations as zeroes, rather than ignoring them outright, which incorrectly brings down the average to 18 when that's calculated at the end.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    So, I put in 2 #N/A values and amended the formula to:

    =SUMPRODUCT((IF(ISERROR($B4:$R4),0,$B4:$R4))*(IFERROR(1/$B3:$R3,0))*($B$1:$R$1=$B$8))/COUNTIFS($B$1:$R$1,$B$8)

    does thiswork for you?
    Attached Files Attached Files

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    There is NO second Tab!!!

  8. #8
    Registered User
    Join Date
    09-25-2009
    Location
    London, England
    MS-Off Ver
    MS Office 365
    Posts
    17

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    I didn't upload the new file when I was making all the other changes needed/that you'd asked for. I can only apologise again.

    In the meantime the new formula still doesn't seem to work and is still producing 18.4. Please let me know if you're seeing something different and I do, still, appreciate your help.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    A change of approach:

    =LET(A,B1:R1,b,B3:R3,C,B4:R4,AVERAGE(TOROW(FILTER(C,A=B8),3)/TOROW(FILTER(b,A=B8),3)))

    Please explain WHY the answer should be anything OTHER than 24.77918 (manually calculated in orange cells).
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    09-25-2009
    Location
    London, England
    MS-Off Ver
    MS Office 365
    Posts
    17

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    Instead of how I'd usually approach this, I'm going to try answering with your approach instead:

    Please explain WHY you've changed approach. Please read the question I originally asked. I did not ask you to rewrite the formula, I asked you to ADD a condition which would just not count the NAs.

    You have not done this!!

  11. #11
    Registered User
    Join Date
    09-25-2009
    Location
    London, England
    MS-Off Ver
    MS Office 365
    Posts
    17

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    And.. eww. That made me feel quite unpleasant.

    This site might cost nothing Glenn, but neither do manners. If you can't help or don't want to that's your prerogative, but for someone who's signature says they do this for fun, you sure do seem to be a miserable man. And use your moderator powers as you wish. It won't change that being true at all.

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    Fair enough. I'll step back at this point. I changed my approach, because my original one didn't work. I could not see how you got your expected results.

    Over to others.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    Try this:

    =SUMPRODUCT((IF(ISERROR($B4:$R4),0,$B4:$R4))*(IFERROR(1/$B3:$R3,0))*($B$1:$R$1=$B$8))/SUMPRODUCT((ISNUMBER($B4:$R4))*(ISNUMBER($B3:$R3)*($B$1:$R$1=$B$8)))
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  14. #14
    Registered User
    Join Date
    09-25-2009
    Location
    London, England
    MS-Off Ver
    MS Office 365
    Posts
    17

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    This works! Thank you so much, I really appreciate it.

    I'll add a thanks to the both of you for your time on this. Have fantastic Easter weekends.
    Last edited by AliGW; 03-27-2024 at 12:05 PM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    You, too.

    Glad to have helped.

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED. You can also access the SOLVED tag by editing the opening post and choosing SOLVED from the drop-down to the left of the title box.

    Also, if you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.

  16. #16
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,428

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    Or try this shorter formula:

    This formula returns also the expected result of 24.5803223741788:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by HansDouwe; 03-27-2024 at 12:20 PM.

  17. #17
    Registered User
    Join Date
    09-25-2009
    Location
    London, England
    MS-Off Ver
    MS Office 365
    Posts
    17

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    Awesome! Thanks Hans, another great solution and one that's even closer to the original formula. Much appreciated!

  18. #18
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,428

    Re: How can I enhance this SUMPRODUCT formula to only counts cells greater than zero?

    Thanks for the feedback and rep . Glad to have helped.

+ 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. Replies: 6
    Last Post: 08-09-2018, 04:43 AM
  2. [SOLVED] Sumproduct formula counts blank cells as instances
    By dlee959 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-24-2014, 01:37 PM
  3. [SOLVED] Sumproduct Function with greater or less than formula?
    By excellenthelp in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-16-2013, 03:17 PM
  4. IF greater than negative value counts blanks as zero
    By fransden in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-15-2013, 03:03 PM
  5. enhance IF formula
    By m1066189 in forum Excel General
    Replies: 4
    Last Post: 06-10-2010, 01:16 PM
  6. Array counts of greater thans
    By Dubbs in forum Excel General
    Replies: 2
    Last Post: 08-19-2009, 07:02 PM
  7. countif forumla that counts if one cell is greater than another
    By JCool in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 05-20-2009, 12:25 PM

Tags for this Thread

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