=SUMIF with date range

Outdoorsman80

Board Regular
Joined
Oct 4, 2014
Messages
61
Office Version
  1. 365
Platform
  1. Windows
I have a workbook with multiple worksheets. I'm creating a Dashboard that pulls from the other sheets. This dashboard needs to present the amount of grain purchased for 2020 (hard coded year).

This is what I have so far to calculate the type of grain in all years, but I need to filter just one year:
Finances.xlsx
KLM
162020
17SumTotal Cost
18Egg Sales Total
19Meaty Food Total4$ 100.82
Dash
Cell Formulas
RangeFormula
L19L19=SUMIF(Items!E2:E4995,"Grain - Broiler Crumbles",Items!I2:I4995)+SUMIF(Items!E2:E4995,"Grain - Starter Mash",Items!I2:I4995)
M19M19=SUM(SUMIF(Items!E2:E5000,{"Grain - Broiler Crumbles","Grain - Starter Mash"},Items!J2:J5000))

As you can see there, it's working but it's pulling totals from 2020 and 2021. Sum should be 3 and total should be $75.

BTW, XL2BB is excellent... :)
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
try using SUMIFS instead of SUMIF, and do:
,YEAR(date-column-in-Items-Sheet),2020)
 
Upvote 0
I have a workbook with multiple worksheets. I'm creating a Dashboard that pulls from the other sheets. This dashboard needs to present the amount of grain purchased for 2020 (hard coded year).

This is what I have so far to calculate the type of grain in all years, but I need to filter just one year:
Finances.xlsx
KLM
162020
17SumTotal Cost
18Egg Sales Total
19Meaty Food Total4$ 100.82
Dash
Cell Formulas
RangeFormula
L19L19=SUMIF(Items!E2:E4995,"Grain - Broiler Crumbles",Items!I2:I4995)+SUMIF(Items!E2:E4995,"Grain - Starter Mash",Items!I2:I4995)
M19M19=SUM(SUMIF(Items!E2:E5000,{"Grain - Broiler Crumbles","Grain - Starter Mash"},Items!J2:J5000))

As you can see there, it's working but it's pulling totals from 2020 and 2021. Sum should be 3 and total should be $75.

BTW, XL2BB is excellent... :)
Unless I'm misinterpreting, your formula doesn't specify a date (year) range as criteria. Use SUMIFS and include whichever column has the year. So for L19:

Excel Formula:
SUM(SUMIFS(Items!I$2:I$4995,Items!$E$2:$E$4995,{"Grain - Broiler Crumbles","Grain - Starter Mash"},columnwithyear,"2020"))
 
Upvote 0
try using SUMIFS instead of SUMIF, and do:
,YEAR(date-column-in-Items-Sheet),2020)
You can't do that with sumifs (or any similar function). If the data contains proper dates then it would need to be in the format of

=SUMIFS(sum range, date range,">="&DATE(2020,1,1), date range, "<="&Date(2020,12,31))

With other criteria added as necessary.
 
Upvote 0
You can't do that with sumifs (or any similar function). If the data contains proper dates then it would need to be in the format of

=SUMIFS(sum range, date range,">="&DATE(2020,1,1), date range, "<="&Date(2020,12,31))

With other criteria added as necessary.
Hi, the column, D, is formatted in proper dates.
 
Upvote 0
Try this in L19, then use the fill handle to drag it to M19.

I've assumed that 2020 is in K16 as i looks merged in the mini sheet.
Excel Formula:
=SUM(SUMIFS(Items!I2:I5000Items!$E2:$E5000,{"Grain - Broiler Crumbles","Grain - Starter Mash"},Items!$D2:$D5000,">="&DATE($K$16,1,1),Items!$D2:$D5000,"<="&Date($K$16,12,31)))
 
Upvote 0
I'm still having some difficulties.
Excel Formula:
=SUM(SUMIFS(Items!E2:E5000,Items!J2:J5000, {"Grain - Broiler Crumbles","Grain - Starter Mash"}, Items!D2:D5000,">=1/1/2020", Items!D2:D5000, "<=12/31/2020"))
The worksheet named Items has the Date in the D column. J Column has the price, E column has the Grain type.

Snippet of the Items Sheet:
Finances.xlsx
DEFGHIJ
6374/1/2020Grain50lb - Soy FreeGreen MountainN/A1$ 22.00
6384/1/2020Grain - Starter Mash50lb - Chick StarterGreen MountainN/A1$ 26.20
6394/1/2020Grain - Broiler Crumbles50lb - Broiler CrumblesGreen MountainN/A1$ 24.21
6626/18/2020Grain - Broiler Crumbles50lb - Broiler CrumblesGreen MountainN/A1$ 24.21
Items


Finances.xlsx
KLM
162020
17SumTotal Cost
18Egg Sales Total
19Meaty Food Total4$ 100.82
Dash
Cell Formulas
RangeFormula
L19L19=SUMIF(Items!E2:E4995,"Grain - Broiler Crumbles",Items!I2:I4995)+SUMIF(Items!E2:E4995,"Grain - Starter Mash",Items!I2:I4995)
M19M19=SUM(SUMIF(Items!E2:E5000,{"Grain - Broiler Crumbles","Grain - Starter Mash"},Items!J2:J5000))
 
Last edited:
Upvote 0
I'm still having some difficulties.
Excel Formula:
=SUM(SUMIFS(Items!E2:E5000,Items!J2:J5000, {"Grain - Broiler Crumbles","Grain - Starter Mash"}, Items!D2:D5000,">=1/1/2020", Items!D2:D5000, "<=12/31/2020"))
The worksheet named Items has the Date in the D column. J Column has the price, E column has the Grain type.

Snippet of the Items Sheet:
Finances.xlsx
DEFGHIJ
6374/1/2020Grain50lb - Soy FreeGreen MountainN/A1$ 22.00
6384/1/2020Grain - Starter Mash50lb - Chick StarterGreen MountainN/A1$ 26.20
6394/1/2020Grain - Broiler Crumbles50lb - Broiler CrumblesGreen MountainN/A1$ 24.21
6626/18/2020Grain - Broiler Crumbles50lb - Broiler CrumblesGreen MountainN/A1$ 24.21
Items


Finances.xlsx
KLM
162020
17SumTotal Cost
18Egg Sales Total
19Meaty Food Total4$ 100.82
Dash
Cell Formulas
RangeFormula
L19L19=SUMIF(Items!E2:E4995,"Grain - Broiler Crumbles",Items!I2:I4995)+SUMIF(Items!E2:E4995,"Grain - Starter Mash",Items!I2:I4995)
M19M19=SUM(SUMIF(Items!E2:E5000,{"Grain - Broiler Crumbles","Grain - Starter Mash"},Items!J2:J5000))
L19=
Excel Formula:
SUM(SUMIFS(Items!I2:I5000,Items!E2:E5000, {"Grain - Broiler Crumbles","Grain - Starter Mash"}, Items!D2:D5000,">="&date(K16,1,1), Items!D2:D5000, "<="&date(K16,12,31)))
M19=
Excel Formula:
 SUM(SUMIFS(Items!J2:J5000,Items!E2:E5000, {"Grain - Broiler Crumbles","Grain - Starter Mash"}, Items!D2:D5000,">="&date(K16,1,1), Items!D2:D5000, "<="&date(K16,12,31)))

Assuming the 2020 year is in cell K16.
 
Upvote 0
Solution
@rilzniak that is the same formula that I suggested earlier.

@Mainer82 your dates are not proper dates, they are text strings. It is unlikely that the formula will recognise them correctly. Ideally, they need to be converted to proper dates, then the formula that I suggested will work as needed.
 
Upvote 0
L19=
Excel Formula:
SUM(SUMIFS(Items!I2:I5000,Items!E2:E5000, {"Grain - Broiler Crumbles","Grain - Starter Mash"}, Items!D2:D5000,">="&date(K16,1,1), Items!D2:D5000, "<="&date(K16,12,31)))
M19=
Excel Formula:
 SUM(SUMIFS(Items!J2:J5000,Items!E2:E5000, {"Grain - Broiler Crumbles","Grain - Starter Mash"}, Items!D2:D5000,">="&date(K16,1,1), Items!D2:D5000, "<="&date(K16,12,31)))

Assuming the 2020 year is in cell K16.
Thank you, I think that I was confused by the K16 reference as my mind was in the Items sheet. Those worked perfectly.... thank you again.
@rilzniak that is the same formula that I suggested earlier.

@Mainer82 your dates are not proper dates, they are text strings. It is unlikely that the formula will recognise them correctly. Ideally, they need to be converted to proper dates, then the formula that I suggested will work as needed.
Thank you as well. As for the dates, the Format Cell is set to Date > Short Date in the Items sheet.
 
Upvote 0

Forum statistics

Threads
1,214,800
Messages
6,121,641
Members
449,044
Latest member
hherna01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top