Closed Thread
Results 1 to 3 of 3

Different results from SumProduct - Why?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-22-2006
    Location
    UK
    MS-Off Ver
    Office 2013
    Posts
    275

    Different results from SumProduct - Why?

    Hi everyone

    I have another small problem with trying to count data from my worksheet.

    As the data is in two columns, I am using SumProduct rather than countif.

    Column A contains individual single text letters.
    Column B contains figures as currency to 2 decimal places, which includes £0.00 as results from a Pivot table calculation plus some cells are temporarily left blank awaiting further data.

    Some rows are left blank in order to separate the information into categories.

    When using this formula:
    =SUMPRODUCT(--($A$5:$A$311="M"),--($B$5:$B$311=0))
    it produces a total of 12 whereas the correct total should be 11.

    The same formula is used with alternatives to the "M" to count data for different categories.

    I have traced the problem to rows where there is an "M" in column A but an adjacent blank cell in column B. The rows where there is an "M" in column A and £0.00 in column B are counted correctly and likewise completely blank rows are ignored.

    These individual totals have to match up with the overall total of column B, using =COUNTIF($B$5:$B$311,0) which gives the correct total by ignoring the blank cells.

    I have found a way round this by using:
    =SUMPRODUCT(--($A$5:$A$311="M"),--($B$5:$B$311=0))-SUMPRODUCT(--($A$5:$A$311="M"),--($B$5:$B$311=""))
    which gives me the required correct result but seems a cumbersome way of solving this problem.

    Can anyone simplify the for me ...Spellbound
    Last edited by VBA Noob; 10-02-2007 at 04:46 AM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,702
    Yes, SUMPRODUCT will treat a blank like a zero, you can add an extra condition to chack that the cells aren't blank, i.e.

    =SUMPRODUCT(--($A$5:$A$311="M"),--($B$5:$B$311=0),--($B$5:B$311<>""))

  3. #3
    Forum Contributor
    Join Date
    03-22-2006
    Location
    UK
    MS-Off Ver
    Office 2013
    Posts
    275
    Hi

    Thanks for quick response.

    I had found some other similar posts on this subject but none that seemed to explain the problem.

    I have now modified the formulas as per your example, which is much tidier than my solution.

    Thanks again.

Closed Thread

Thread Information

Users Browsing this Thread

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

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