Excel/Function SUMIFS

Advertisement


Question
Hi Tom,
I have a recent question.
I have two sheets: "Data" with the single values, "Summary" as an overview. In the sheet "Summary" I use the function SUMPRODUCT for which I would like to substitute with the function SUMIFS.

Sheet construction "Data"
Column A   column B   column C
Date       customer   Credit
01.01.2013 AAA        101
15.01.2013 BBB        80
05.04.2013 CCC        300
20.05.2013 BBB        250
etc.
27.12.2014 AAA        130
The sheet "Data" contains ca 10000 records of 2010 till this day.
There are 600 customers.

Sheet construction "Summary"
Column A  column B     column  C     column  D .. column Y
Customer  January 2013 February 2013 March 2013...December 2014
AAA
BBB
CCC

The cells B1, C1 have the values 01.01.2013, 01.02.2013 etc., they are formatted MMMMYYYY

I use the following code:
Sub test ()
 With Worksheets ("Summary").Range ("B2").Resize (3, 24)
   '.Formula = "=Sumproduct (-(year (Data! $A$2: $ A$995) =year (B$1)), _
   '- (month (Data! $A$2: $ A$995) =month (B$1)), _
   '- (Data! $B$2: $ B$995 = $ A2), Data! $C$2: $ C$995)"
    
    .Formula = "=SUMIFS (Data! $C$2: $ C$995, Data! $A$2: $ A$995, year (B$1), Data! $A$2: $ A$995, Month (B$1), Data! $B$2: $ B$995, $A2)"
      
   '.Formula =.Value
  
 With
Sub

The function SUMPRODUCT proves the right result. The function SUMIFS proves the values 0. My function is apparently wrong. From cell B1 the year as criterion1, also from cell B1 the month as criterion2, from cell A2 as criterion3 the customer.
I would be very grateful for a correction of the above function SUMIFS or, however, a tip.
Volker

Answer
=SUMIFS(C:C,B:B,">="&DATE(YEAR(D1),MONTH(D1),1),B:B,"<"&DATE(YEAR(D1),MONTH(D1)+1,1))

in your sumproduct, your test is

-(year(Data!$A$2:$A$995)=year(B$1))
and
- (month (Data!$A$2:$A$995)=month(B$1))
and
- (Data!$B$2:$B$995=$A2)

But in your sumifs you don't use
Year(Data!$A$2:$A$995),year(B$1)
or
Month(Data!$A$2:$A$995,Month(B$2)

=SUMIFS (Data!$C$2:$C$995,Data!$A$2:$A$995,year(B$1),Data!$A$2:$A$995,Month(B$1),Data!$B$2:$B$995,$A2)

so
=SUMIFS (Data!$C$2:$C$995,year(Data!$A$2:$A$995),year(B$1),Month(Data!$A$2:$A$995),Month(B$1),Data!$B$2:$B$995,$A2)

But of course you probably didn't do that because it doesn't work.  The formula won't accept functions applied to the  multi-cell arguments.

so the solution is to modify the criteria.  You want to find the date in A2:A995 that is greater than or equal to the first day of the month of interest and less than the first day of the next month.  

You can do this with

=SUMIFS (Data!$C$2:$C$995,Data!$A$2:$A$995,">="&Date(year(B$1),Month(B$1),1),Data!$A$2:$A$995,"<"&Date(year(B$1),Month(B$1)+1,1),Data!$B$2:$B$995,$A2)

if you put that in code you would need to double the double quotes.  So

 .Formula = "=SUMIFS (Data!$C$2:$C$995,Data!$A$2:$A$995,year(B$1),Data!$A$2:$A$995,Month(B$1),Data!$B$2:$B$995,$A2)"

would become

 .Formula = "=SUMIFS (Data!$C$2:$C$995,Data!$A$2:$A$995,"">=""&Date(year(B$1),Month(B$1),1),Data!$A$2:$A$995,""<""&Date(year(B$1),Month(B$1)+1,1),Data!$B$2:$B$995,$A2)"



--
Regards,
Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.