Excel help: sum numbers if within date range - excel

I have a spreadsheet of expenses, sorted by categories in columns C through P (eg, "rentals" in column C, "catering" in column D, etc). The date is in column A. I want to find the sum of all expenses in columns C:P, but only those where the date is between a certain range. Here's what I tried:
=SUMIFS(C:P,A:A,">=1-Feb-2018",A:A,"<=28-Feb-2018")
but I get a #VALUE! error. I think it is because C:P is a different size selection than A:A? It works if I do
=SUMIFS(C:C,A:A,">=1-Feb-2018",A:A,"<=28-Feb-2018")
Is there another formula that will work without using
= SUMIFS(C:C,A:A,">=1-Feb-2018",A:A,"<=28-Feb-2018")
+SUMIFS(D:D,A:A,">=1-Feb-2018",A:A,"<=28-Feb-2018")
+SUMIFS(E:E,A:A,">=1-Feb-2018",A:A,"<=28-Feb-2018")...

I'm not sure if you can get it to work with a SUMIFS, but here's a SUMPRODUCT version:
=SUMPRODUCT(C:P * (A:A <= DATE(2018,2,28)) * (A:A >= DATE(2018,2,1)))
You could also create a helper column, say Q, that sums C:P and use your SUMIFS on that.
=SUMIFS(Q:Q, A:A, ">=1-Feb-2018", A:A, "<=28-Feb-2018")

This is because 1-Feb-2018 is not recognised by Excel as a date - it will be giving a #Name? error inside the formula, as it's not even a String (">=""1-Feb-2018"""))
1st February 2018 is treated by Excel as the number 43132 (Number of days since 31/12/1899), but is then Formatted as d-mmm-yyyy to display as 1-Feb-2018. You can either:
Type the number: ">=43132"
Add 0 to a string version to convert it: ">=(0+""1-Feb-2018"")"
Use the DATE function: ">=" & DATE(2018,2,1)
All 3 of these work with SUMIFS, like so:
=SUMIFS(C:P, A:A, ">=43132", A:A, "<=43159")
=SUMIFS(C:P, A:A, ">=(0+""01-Feb-2018"")", A:A,
"<=(0+""28-Feb-2018"")")
=SUMIFS(C:P, A:A, ">=" & DATE(2018,2,1), A:A, "<=" &
DATE(2018,2,28))
Personally, I recommend method 3

Related

Can SUMIFS calculate data from current month with 2 or more criteria?

I have a spreadsheet that uses a few SUMIFS formulas to calculate data based on 2 criteria and a normal range. Currently I'm having to change this manually every month to capture metrics of tickets reported that meet some of those criteria. Ideally i'd like to implement some logic to only calculate data that has dates from the current month.
Here's my original sumifs:
=SUMIFS($G$2:$G$100,$A$2:$A$100,"primary",B2:B100,"little")
=SUMIFS($G$2:$G$100,$A$2:$A$100,"primary",B2:B100,"panic")
etc..
I was told something to the extent of this would get me where I needed to be, but it doesn't seem to be actually calculating only data with dates within this month.
=SUMIFS($G$2:$G$100,$A$2:$A$100,"primary*",$B$2:$B$101,"little")+SUMIFS($G$2:$G$100,$F$2:$F$100,">="&DATE(YEAR(TODAY()),MONTH(TODAY()),1))
Any help would be greatly appreciated!!
Spreadsheet_data
Why not try using the Incredibly Versatile SUMPRODUCT Function here,
Formula used in cell I2
=SUMPRODUCT(($G$2:$G$9)*($A$2:$A$9=$J2)*($B$2:$B$9=$K2)*
(TEXT($F$2:$F$9,"mmmmyyyy")=$I$1&YEAR(TODAY())))
The SUMPRODUCT function simply multiplies arrays together and returns the sum of products. If only one array is supplied, SUMPRODUCT will simply sum the items in the array. Up to 30 ranges or arrays can be supplied.
It may seem boring, complex, and even pointless. But SUMPRODUCT is an amazingly versatile function with many uses. Because it will handle arrays gracefully, you can use it to process ranges of cells in clever, elegant ways. It can be used to count and sum like COUNTIFS or SUMIFS, but with more flexibility.
So, let me go through you a bit what the formula does,
Array 1
($A$2:$A$9=$J2) {TRUE;FALSE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE}
Array 2
($B$2:$B$9=$K2) {TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;FALSE}
Array 3
(TEXT($F$2:$F$9,"mmmmyyyy")=$I$1&YEAR(TODAY()))
{FALSE;TRUE;FALSE;FALSE;FALSE;TRUE;TRUE;TRUE}
And this is the whole part which is wrapped within SUMPRODUCT
($G$2:$G$9)*($A$2:$A$9=$J2)*($B$2:$B$9=$K2)*(TEXT($F$2:$F$9,"mmmmyyyy")=$I$1&YEAR(TODAY()))
When you select this part and press F9, it evaluates and shows you an array of numbers
{0;0;0;0;0;0;12;0}
Basically its creates an array of TRUE's & FALSE's and then multiplies with the corresponding values to give you the exact output which you need!
Also why you need to use SUMPRODUCT Function ---> Let me tell about it more
It never gives an error for text values unless you are not using a double negative or double minus, I always say SUMPRODUCT is much versatile function than other, it can be clubbed with many other excel functions without any issue.
The double negative (--) is one of several ways to coerce TRUE and FALSE values into their numeric equivalents, 1 and 0. One we have 1s and 0s, we can perform various operations on the arrays with Boolean logic. The table below shows the result in array1,array2, array3 based on the formula above, after the double negative (--) has changed the TRUE and FALSE values to 1s and 0s.
Yep, you can!
You'll need formulas to get the first date of this month and the next month:
Date(Year(Today()), Month(Today()) , 1)) -- first day of this month
Date(Year(Today()), Month(Today()) + 1, 1)) -- first day of next month
(This wraps the months intelligently i.e. Date(2021, 13, 1) is 2022-01-01)
You can then use these with greater-than and less-than operators within SUMIFS:
= SUMIFS(
value_column,
date_column, ">=" & Date(Year(Today()), Month(Today()) , 1),
date_column, "<" & Date(Year(Today()), Month(Today()) + 1, 1)
)
For example:
= SUMIFS(
G:G,
F:F, ">=" & Date(Year(Today()), Month(Today()) , 1),
F:F, "<" & Date(Year(Today()), Month(Today()) + 1, 1),
A:A, "primary",
B:B, "panic"
)
So here it's picking up the 33 and 57 to calculate the sum of 90.
Why this instead of SumProduct?
You can refer to entire columns e.g. G:G rather than a fixed range e.g. G$2:G$9999. SumProduct gives a #VALUE! error if any of the rows contain text, i.e. the column labels in the first row. SumIfs happily ignores the text.
Edit:
There may be a fault in this formula:
=SUMIFS($G$2:$G$100,$A$2:$A$100,"primary*",$B$2:$B$101,"little")+SUMIFS($G$2:$G$100,$F$2:$F$100,">="&DATE(YEAR(TODAY()),MONTH(TODAY()),1))
Making the format a little friendlier:
= SUMIFS(
$G$2:$G$100,
$A$2:$A$100, "primary*",
$B$2:$B$101, "little"
)
+ SUMIFS(
$G$2:$G$100,
$F$2:$F$100, ">=" & DATE(YEAR(TODAY()),MONTH(TODAY()),1)
)
It's adding all the Primary Littles from any month, and then also adding all the entries from this month onwards - double-counting any Primary Littles it's already counted.

Excel: Need to sum based on date range in two columns (between dates) over one column

My raw data is this:
My desired result is this:
Explanation of desired result:
So, for example if 01/07/2018 falls between the date from and date to and it's under package A, we will get the number and finally total them together. So as you can see in my raw data, 01/07/2018 belongs to Mr.X and Ms.Z, so the total sum under package A for 01/07/2018 is 2. The next date, 02/07/2018 and under package A, we have Mr.X only so the total sum is 1.
I've tried the following formula:
=SUMIFS(D3:D9, B3:B9, ">=" &J3, C3:C9, "<=" &J3)
But it just resulted in 0. How can I get the correct result as shown in my desired result?
J3 is just a dummy column with a date. For e.g 01/07/2018. D3:D9 is column package A, B3:B9 is column date from, C3:C9 is column date to
You just need to reverse the < and > signs:
=SUMIFS(D3:D9, B3:B9, "<=" &J3, C3:C9, ">=" &J3)
then put some dollar signs in so it will give the right answer when you pull it across and down
=SUMIFS(D$3:D$9, $B$3:$B$9, "<=" &$J3, $C$3:$C$9, ">=" &$J3)

SumIF + Index + Match formula

I have the following table and I'm trying to get a formula so that I can get the sum of a center's result between two dates i.e. Sum all numbers for Bunbury between dates 08-05-17 and 06-05-17 (Result: 950). I've used the following formula but it gives me #VALUE!
My formula:
=SUMIFS(INDEX(B:G,MATCH("Bunbury",$A15:$BC15,0),0),$A$16:$A$21,"<=" & $J3,$A$16:$A$21,">=" & $I3)
enter image description here
Your match should match the column, not the row in B:G.
=SUMIFS(INDEX($B$16:$G$21, 0, MATCH("Bunbury", $B$15:$G$15, 0)), $A$16:$A$21,"<="&$J3, $A$16:$A$21,">="&$I3)
'alternate
=SUMIFS(INDEX($B:$G, 0, MATCH("Bunbury", $B$15:$G$15, 0)), $A:$A,"<="&$J3, $A:$A,">="&$I3)
There's also no need to look further than column G for a match and you should start looking in column B; e.g. $B15:$G15. J3 should be the end date and I3 the start date (not evident from your sample image).
I missed one problem the first time around. INDEX cannot reference all of the rows in B:G; it can only reference the same number of rows as $A$16:$A$21 (the date comparison range). Alternately, if there is no rogue data that would skew results, the date comparison ranges could be made full column. They have to be comparable ranges.

SumIfs in Excel

I have a requirement to sum all the cells in a column from a sheet called Raw Data. But only if a few conditions exist.
The value in Raw Data column B matches the value of a offset from the current cell
The Month of the date in Raw Data Column C is less than or equal to H2
The Year of the date in Raw Data Column C is less than or equal to H2
Here is the formula I have assembled thus far:
=SUMIFS('Raw Data'!$D:$D,'Raw Data'!$B:$B,OFFSET(INDIRECT(ADDRESS(ROW(), COLUMN())),0,-4),MONTH('Raw Data'!$C:$C),<=MONTH($H$2),YEAR('Raw Data'!$C:$C),<=YEAR($H$2))
It could be a simple syntax error, but I don;t think it is. I keep getting a generic "There is a problem with the formula" error.
Can I get some help?
With SUMIFS the range expects a range not an array so MONTH('Raw Data'!$C:$C) and YEAR('Raw Data'!$C:$C) will not work.
Also when the others are expecting a string so you must use quotes and concatenate the criteria: "<=" & value
In this case we want everything less than the 1st of the next month:
"<" & EOMONTH($H$2,0)+1
Use this:
=SUMIFS('Raw Data'!$D:$D,'Raw Data'!$B:$B,OFFSET(INDIRECT(ADDRESS(ROW(), COLUMN())),0,-4),'Raw Data'!$C:$C,"<" & EOMONTH($H$2,0)+1)

SUMIFS within a date range

I am working on a excel file for my monthly budget. I am exporting my monthly transactions into a CSV file and then copying it over.
I have a tab for each month and all my categorizes that I am budgeting for. I then copy over the csv file to a tab called transactions in my budget workbook. Then I have a drop down list with all the categorizes from my monthly categories. Once I have categorized all my transactions that will total up on the corresponding budget sheet.
The issue I am having a hard time with is how do I create a specific equation that will recognize the month and then the specific category item. For an example "His - Income" I can easily use a sumif to get that information from a list, but how do I now separate further it for April only.
The data is organized on a tab by Date in column "A", description in column "B", and amount in "D". I am looking for an equation that will find "His - income" for 4/1/2015 to 4/30/2015.
You want to use a SUMIFS
SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2,criteria2])
With one IF for the category, and two more for the date range. I will look something like this:
=SUMIFS(D1:D50, B1:50,"=His - income",A1:A50,">=4/1/2015",A1:A50,"<=4/1/2015")
I would change all the hard coded ranges (e.g. D1:D50 to named ranges) as well as the dates. If you put the dates in a cell it will change the formula to something like this: BudgetDates,"<="&F$1 (notice the ampersand)
The SUMIFS function can use operators other than equals; equals is just the default. With 01-Apr-2015 in J1 (sometimes 04/01/2015 formatted a mmmm) and His - Income in K1, you could use one of the following.
=sumifs(D:D, B:B, K1, A:A, ">="&J1, A:A, "<"&edate(J1, 1))
=sumifs(D:D, B:B, K1, A:A, ">="&date(2015, 4, 1), A:A, "<"&date(2015, 5, 1))
=sumifs(D:D, B:B, "His - Income", A:A, ">=4/1/2015", A:A, "<5/1/2015")
Unless you want to use it as a visual reminder, the = for exact martch is unnecessary. Typically, the upper limit of the date range is less than one day higher in case the dates contain times as well. The EDATE function will raise or lower a date by a number of months the equal to the integer in its months parameter.
For all intents and purposes, there is no adverse effect when using full column references with SUMIFS.

Resources