Solved

Question about Sumproduct Function

Posted on 2013-12-27
2
437 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
ID: 39743005
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
ID: 39743155
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
My experience with Windows 10 over a one year period and suggestions for smooth operation
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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

13 Experts available now in Live!

Get 1:1 Help Now