I'm started with the following:
=SUMIF(MONTH('Inventory'!K:K),B5,'Inventory'!M:M)
where MONTH('Inventory'!K:K) is supposed to return the month number (Jan=1, Feb=2, etc.) from a mm/dd/yyyy date column, B5 holds the month number I want to sum by, and 'Inventory'!M:M is an amount column.
In place of MONTH('Inventory'!K:K) I also tried LEFT('Inventory'!K:K, 1) with no luck.
I though possibly that the MONTH expression is returning a value where Excel is looking for a Range, but I wasn't able to find a workaround. Tried the following, which also didn't work:
=SUMIF('Inventory'!K:K,MONTH('Inventory'!K:K)=B5,'Inventory'!M:M)
While a pivot could work, I wanted the user to be able to just add to the Inventory tab without worrying about refreshing.
Create start and end dates from the numerical month in B5 rather than trying to convert the dates in column K to numerical month integers.
=SUMIFS('Inventory'!M:M, 'Inventory'!K:K, ">="&date(2017, B5, 1), 'Inventory'!K:K, "<"&date(2017, B5+1, 1))
Note SUMIFS, not SUMIF; they have a slightly different syntax.
Alternately, use SUMPRODUCT.
=SUMPRODUCT((MONTH('Inventory'!K:K)=B5)*('Inventory'!M:M))
You should trim down the full column references with SUMPRODUCT or be prepared to suffer calculation lag.
=SUMPRODUCT((MONTH('Inventory'!K2:index('Inventory'!K:K, match(1e99, 'Inventory'!K:K)))=B5)*('Inventory'!M2:index('Inventory'!M:M, match(1e99, 'Inventory'!K:K))))
Depends what you need, but here are two options that don't restrict you to one year's worth of months:
1) Create a helper column next to 'Inventory'!K:K to extract the month, then write your SUMIF using that column as the range.
2) Use SUMPRODUCT like so:
=SUMPRODUCT((MONTH('Inventory'!K:K)=B5)*'Inventory'!M:M)
Related
=COUNTIFS(NETWORKDAYS(C:C, TODAY(), 1),">=" & 5)
I am trying to use something like the above to count any values in Column C (Date column of my dataset) where the working days from then to todays date is greater than 5. Can this be done without creating a working days column?
It's actually not so obvious but NETWORKDAYS does not work with ranges. Arrays however are completely fine. See this post on SuperUser too.
So in your case you could simply use:
=SUMPRODUCT(--(NETWORKDAYS(C:C+0,TODAY())>=5))
Obviously it's better not to reference the whole of column C. Depending if one has Excel O365, you could also just use =SUM instead of =SUMPRODUCT.
I'd like to include a SUMPRODUCT within a SUMIF formula.
I'm trying to calculate the sum of product of two cells for a specific row, within a date range.
Right now, I have:
=SUMIFS(A12:E12,$A$10:$E$10,">="&DATE(2018,10,1), $A$10:$E$10, "<="&DATE(2019,9,30))
It's currently summing the entire row for the parts that fall within these dates. I'd like it to sum the entire row for the part falling within these dates, but instead of just summing the row, I'd like it to sum the product of A12 * A9, B12 * B9, etc.
Ideally it would look something like this:
=SUMIFS(SUMPRODUCT($A$9:$E$9,A12:E12),$A$10:$E$10,">="&DATE(2018,10,1), $A$10:$E$10, "<="&DATE(2019,9,30))
But that doesn't work.
Any suggestions would be great, thanks!
Looks like a sumproduct would be sufficient, as it can also take conditions.
=SUMPRODUCT(($A$9:$E$9)*(A12:E12)*($A$10:$E$10>=DATE(2018,10,1))*($A$10:$E$10<=DATE(2019,9,30)))
But without your sample data i can't tell if this works would work on your data. For my sample data the first 2 arrays got multiplied and summed up if the date was between the 2 conditions.
Use an old style array formula with nested IF conditions.They are much more versatile than trying to marry forced cyclic processing with functions that already use cyclic processing.
=SUM(IF($A$10:$E$10>=DATE(2018,10,1), IF($A$10:$E$10<DATE(2019,10,1), A9:E9*B12:E12)))
Finish this with ctrl+shift+enter, not just enter.
In case the dates in A10:E10 contin a time value I've modified your less than to include all of 30-Sep-2019 up to midnight.
I have excel data in the following format
Date Amount
01-Jan-16 23.94
12-Jan-16 17.96
26-Jan-16 32.92
03-Feb-16 38.90
20-Feb-16 62.27
26-Feb-16 45.89
I would like to sum the amount field for specific months, that is I would like to sum up the amount in January and also in February separately.
This is the code I have tried thus far which I found in a previously asked question (see Excel Formula to SUMIF date falls in particular month).
=SUM(IF(MONTH(A:A)=1,B:B,0))
It works for January but when I change 1 to 2 it returns zero.
=SUM(IF(MONTH(A:A)=2,B:B,0))
Would sumifs work better?
Here are two other ways of doing it:-
=SUMPRODUCT((MONTH(A2:A10)=1)*B2:B10)
and
=SUMIFS(B2:B10,A2:A10,">="&DATE(2016,1,1),A2:A10,"<"&DATE(2016,2,1))
Change as necessary to get totals for other months.
I have put the results next to the original array formula in this screen shot:-
Use specific range rather than full column. You must use the formula as array formula.
=SUM(IF(MONTH($A$2:$A$1000)=1,$B$2:$B$1000,0))
Press CTRL+SHIFT+ENTER to evaluate the formula as array formula.
Could you help me to fix this excel error?
I'm trying to write a SUMIFS function. On my first page I have all my banking transaction sorted by date from 2011 to 2014. All transactions belong to one and only one category.
I need to sum my value in Sum_range only if my two criteria are true.
The year of the date should be the year specified in a cell
The category should be the category specified in another cell
I know the problem is about the year or the date because I can sum with my second condition only.
While SUMPRODUCT can use YEAR like this,
=SUMPRODUCT((YEAR('Transactions LU'!A:A)=A12)*('Transactions LU'!J:J=C11), 'Transactions LU'!H:H)
... you won't want to use full column references (slower) and SUMPRODUCT can easily break trying to perform math on an extra text value. SUMIFS is vastly more efficient and in the area of 30% of the calculation load.
=SUMIFS('Transactions LU'!H:H, 'Transactions LU'!A:A, ">="&DATE(A12, 1, 1), 'Transactions LU'!A:A, "<"&DATE(A12 +1, 1, 1), 'Transactions LU'!J:J, C11)
The second SUMIFS formula is much preferred.
Don't 100% understand the issue - but if it is really only the Year column that is making trouble try using Value(A12) or if that doesn't work TEXT(A12;0) this either converts the value to text or into number format. It depends whether your data column is in number or text format. (probably try TEXT first).
Let's say that I have a list of dates starting from A1 and going across...
1/3/2014
2/5/2014
5/5/2015
8/10/2016
...
I'd like to count the number of times a certain month appears in this range. My current solution is that the row below it just contains =MONTH(x1), where x is the column, and then I call a COUNTIF on that row.
I don't think that's so bad of a solution, but it does require a whole bunch of extra cells just to calculate months in my spreadsheet, which isn't really necessary for anything else.
So basically, is there any way to do something along the lines of =COUNTIF(MONTH(range),5) to count, for example, the number of times something occurs in May?
No, you can't do that, COUNTIF function requires a range as first argument - any operation on a range (like using MONTH function) converts that range to an array that COUNTIF doesn't accept
Possible alternative are to use SUMPRODUCT e.g.
=SUMPRODUCT((MONTH(range)=5)+0)
or COUNTIFS like this
=COUNTIFS(range,">="&Z1,range,"<"&EOMONTH(Z1,0)+1)
where Z1 is 1st of the month to count, e.g. 1-May-2013
Of course the SUMPRODUCT version doesn't take account of the year (although you could add that in) while COUNTIFS does
Explanation
In SUMPRODUCT when you use an expression like MONTH(range)=5 that returns an "array" of TRUE/FALSE values like {TRUE;FALSE;FALSE;TRUE}....but SUMPRODUCT here only sums numbers so we need a way to "co-erce" TRUE to 1 and FALSE to 0. You can do that with any mathematical operation that doesn't change the value, e.g. +0, *1 or you can add -- to the front like this:
=SUMPRODUCT(--(MONTH(range)=5))
so we get something like
=SUMPRODUCT(--({TRUE;FALSE;FALSE;TRUE}))
...and that becomes
=SUMPRODUCT({1;0;0;1})
and then SUMPRODUCT sums those values to get 2, i.e. the number of dates in May.
SUMPRODUCT is preferred to SUM purely because you don't need to "array enter" the formula with CTRL+SHIFT+ENTER
See here for a good explanation of SUMPRODUCT and it's many uses