Solved

Question about Sumproduct Function

Posted on 2013-12-27
2
424 Views
Last Modified: 2013-12-28
Hi Experts,

The function below attempts to use Trim function on a range name so that I can indent the referenced cell (the range has no indents). It fails as soon as I add a space to the name in A11.

In another case I tried to extract the year from a date by using the Year function in a similar way to what you see below. That also failed and I had to create a new column in the data.

=SUMPRODUCT(-(TRIM(tblSalariesName)=$A11),-(tblSalariesYear=B$3),(tblSalariesAmount))

I admit to being a Lotus 1-2-3 user when I can be wherein all of this is quite simple and elegant.

Thanks for any help and have a happy new year
0
Comment
Question by:rjfields
2 Comments
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
Comment Utility
You would need to apply TRIM to A11 too, try like this

=SUMPRODUCT(-(TRIM(tblSalariesName)=TRIM($A11)),-(tblSalariesYear=B$3),tblSalariesAmount)

Note that TRIM will remove leading and trailing zeroes and also reduce repeated consecutive internal spaces to a single space, so that might affect your comparison

If you don't want to have a separate column for the year you should be able to use this version

=SUMPRODUCT(-(TRIM(tblSalariesName)=TRIM($A11)),-(YEAR(tblSalariesDate)=B$3),tblSalariesAmount)

....but that will fail if tblSalariesDate includes any text values (e.g. a header) because YEAR function applied to text gives #VALUE! error, an alternative is to use TEXT function which will be OK with headers, i.e.

=SUMPRODUCT(-(TRIM(tblSalariesName)=TRIM($A11)),-(TEXT(tblSalariesDate,"yyyy")=B$3&""),tblSalariesAmount)

regards, barry

PS using SUMPRODUCT with a single - in front of each condition is valid but it's more normal to double those to --

If you use a single - you need to make sure you have an even number of conditions otherwise your result might be negated (e.g. you get -2000 instead of 2000)
0
 

Author Closing Comment

by:rjfields
Comment Utility
Thank you very much.

It turns out I made a hugely lame mistake misplacing the Trim function. OY! I caught it looking at your example. Also, you are right about the unary operator. I had an even number of them otherwise one needs to use a double unary (--) operator.

12/27
I did try to cut and paste your suggestion for the Year function above after redefining the range to exclude the column header. I also shortened the range to 10 rows and verified that I had valid dates within it. I still get #value as a return complaining about a datatype error.

12/28

Indeed you were correct about the header in the range definition causing the #value error. I just needed to take the additional step of adjusting all the other relevant ranges to omit the header cell as well to preserve the symmetry of the query.

Again thanks much
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

This collection of functions covers all the normal rounding methods of just about any numeric value.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now