SUMIFS within a date range - excel

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.

Related

Can you define names for dates in Excel to use them in formulas?

I hope you are all well.
I have a question. I have a list with many payments listed on column A with dates (format day/month/year) in column B and I would like to use a formula which says something like
IF= A1 = Q2, "pay", "don't pay" , IF= A2 = Q2, "pay", "don't pay"...
Q2 means quarter 2
Could I define names for dates? For example Q2 would be 01/04/2021 - 30/06/2021 so all the dates within that range would be named Q2.
Best regards
You may try anyone of the approaches as explained below, the first one is using ROUNDUP & MONTH Function and the other one is using DEFINED NAMES.
First Approach ---> Using ROUNDUP & MONTH FUNCTION
• Formula used in cell B3
="Q"&ROUNDUP(MONTH(A3)/3,0)
• Formula used in cell C3
=IF("Q"&ROUNDUP(MONTH(A3)/3,0)="Q2","Pay","Don't Pay")
So you can see i have used two columns in the first approach just to make it understandable, therefore just wrap the formula in cell B3 within an IF logic as shown in cell C3 to get the desired output.
Second Approach --> Using DEFINED NAMES & SUMPRODUCT FUNCTION
• Formula used in Defined Names
=ROW(INDIRECT(--TEXT("01-04-2021","dd/mm/yyyy")&":"&--TEXT("30-06-2021","dd/mm/yyyy")))
So you can see I have Defined the Quarter 2 as _Q2 and the reason is a name must either begin with a letter, underscore (_), or backslash (). If a name begins with anything else, Excel will throws an error.
Therefore the formula used in cell D3
=SUMPRODUCT((A3>=_Q2)*(A3<=_Q2))
The above formula creates an array of TRUE's & FALSE's and multiplies to return the corresponding values.
Now the above formula when wrapped within an IF Function it gives us the requisite output as desired,
Formula used in cell E3 (Same it can be done in one cell, to make it understandable i have used two columns)
=IF(SUMPRODUCT((A3>=_Q2)*(A3<=_Q2))=1,"Pay","Don't Pay")
So this is how you can used a Defined names for dates in excel and then use the same within a formula.
This solution does not provide names for dates but it might meet your needs:
Make sure column A is formatted as a date, then use this formula to get the quarter from the month (this array allows you to set Q1 if it is not the same as calendar quarters):
="Q"&CHOOSE(MONTH(A1),1,1,1,2,2,2,3,3,3,4,4,4)
Then test the value of this column:
=if(C1="Q1", "Pay", "Do not Pay")
You could also create a cell at the top of your spreadsheet and name it current_quarter. Then you would type in the current quarter "Q1", "Q2", ... and your formula would be
=if(C1= current_quarter, "Pay", "Do Not Pay")
You are using standard calendar month quarters, so we can get the quarter number easily by dividing and rounding up.
=ROUNDUP(MONTH(A1)/3,0)
You can then use this number in your IF function.
=IF(ROUNDUP(MONTH(A1)/3,0)=2,"Pay","Don't Pay")

Excel- Sum groups of similar cell contents using wildcards

I am trying to sum the amounts in column B based on the types of symbols in column A. Any symbol with "EW" at the start needs to be grouped and by date month - see column D. The second symbol comes in two formats but also needs to be grouped, so "OES" and "OMSX" needs to be grouped together and with their date month. I know I need wildcards here but I cannot get this to work.
EDIT, correct EW, accidentally had "EWS" before, apologies to anyone who responded
Thius should work if you can get your data corrected.
=SUMIFS(B:B, A:A, REPLACE(D2, FIND(" ", D2), LEN(D2), "*"), A:A, REPLACE(D2, 1, FIND(" ", D2), "*")&"*")

Excel help: sum numbers if within date range

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

Calculations for every unique/distinct values

I have a very large data set that I need to work with and in my calculations three columns are of interest. Let's call the different columns [A], [B] and [C]. In [A] I have a list of different company names, where each company name might occur several times. I have created a table for the data and sorted the company names alphabetically. Let's say I have the company name X in A2:A5 and the calculation that needs to be done is SUMPRODUCT(B2:B5;C2:C5)/SUM(C2:C5). How do I calculate this for every unique/distinct company name and present the result in a nice way?
Use the following formula in a new column D for example in D2:
=IF(A2<>A1,SUMPRODUCT(--($A$2:$A$10=A2)*$B$2:$B$10*$C$2:$C$10)/SUMIF($A$2:$A$10,A2,$C$2:$C$10),"")
and drag it down whenever the value in A changes it will write a result
Change A2:A10, B2:B10 and C2:C10 to correspond your last row and keep $ for fixed references
To correspond to your settings I wrote ";" in the following:
=IF(A2<>A1;SUMPRODUCT(--($A$2:$A$10=A2)*$B$2:$B$10*$C$2:$C$10)/SUMIF($A$2:$A$10;A2;$C$2:$C$10);"")
Put two INDEX functions together with a : for the range.
=IF(A2<>A3, SUMPRODUCT(INDEX(B:B, MATCH(A2, A:A, 0)):INDEX(B:B, MATCH(A2&"z", A:A)), INDEX(C:C, MATCH(A2, A:A, 0)):INDEX(C:C, MATCH(A2&"z", A:A)))/SUMIFS(C:C, A:A, A2), TEXT(,))
The first occurrence is found with,
INDEX(B:B, MATCH(A2, A:A, 0))
The last occurrence (on sorted data) is found with,
INDEX(B:B, MATCH(A2&"z", A:A))
Note that I changed your SUM to a SUMIFS to make life a little easier.

Set mileage destination displaying

I have some experience with excel but its very limited. I have a list of regular To & From destinations setup as historical data along with the mileage between.
What I have is basically cell A1 WIGAN + cell B1 LUTTERWORTH in Sheet 2 and I want a formula to match both of these from Sheet 1 and display the mileage. If the journey has no history then to display a NIL value.
It sounds simple but as yet I've not located anything that works or been able to work it out myself.
Try this:
=INDEX('Sheet1'!C:C,MATCH("NEWHOUSE",IF('Sheet1'!A:A = "WIGAN",'Sheet1'!B:B),0))
It is an array formula and must be confirmed with Ctrl-Shift-Enter.
Change the Column references to the actual reference; change C:C to $C$2:$C$1000. It will speed it up.
You could minimize the cross-reference table of mileage values by adding a reversed lookup if the first fails.
    
In Sheet5!C2 as,
=INDEX(Mileage!C:C, IFERROR(AGGREGATE(15, 6, ROW($1:$99)/((Mileage!$A$1:$A$99=A2)*(Mileage!$B$1:$B$99=B2)), 1), AGGREGATE(15, 6, ROW($1:$99)/((Mileage!$A$1:$A$99=B2)*(Mileage!$B$1:$B$99=A2)), 1)))

Resources