I have a table of mortgage loans in Excel. I want to sum the loan amounts(B:B) for loans whose lock dates(D:D) were in the previous month. I am trying to use the "SumIF" function to pull criteria from a different cell as below:
=SUMIF(range,"*"&A1&"*",sum_range)
But I want to pull a "date between previous month start and previous month end" range. I've used this for another function and it has worked.
D:D,">="&EOMONTH(TODAY(),-2)+1,D:D,"<"&EOMONTH(TODAY(),-1)+1
Now, I am trying to infuse the latter function into the first, something like this, but it is not returning anything. Any help would be much appreciated!
=SUMIF(Data!D:D,"*">="&EOMONTH(TODAY(),-2)+1,Data!D:D,"<"&EOMONTH(TODAY(),-1)+1)*",Data!B:B)
Use SUMIFS when you have multiple criteria, and from your explanation, it seems like you don't need the wildcard "*".
=SUMIFS(B:B,D:D,">="&EOMONTH(TODAY(),-2)+1,D:D,"<"&EOMONTH(TODAY(),-1)+1)
Related
I am building a new dashboard that refreshes on a daily basis. The dashboard includes current month data as well as prior month data. However, I need to try a few different scenarios in terms of dates to ensure that month transitions work with no problem. For example, I would like to know what my formulas would do when it is the first day of the month, and the second day of the month with different conditions such as the 1st day being weekends or holidays, etc, where I won't have any data, which would lead to errors.
I tried fixing formulas, but there were way too many formulas involved and related to each other. Also data is being pulled from SQL server, where I am also using GETDATE().
For example, one of my formulas show
=YEAR(TODAY()-1)&IF(MONTH(TODAY()-1)<10,0&MONTH(TODAY()-1),MONTH(TODAY()-1))
to get the year & month (e.g. 201904 for 2019 April). This is one of many formulas that has today() built in
In sum, I am wondering if I can change the date that Excel is reading off. For example, I have a formula with =TODAY() - I want this formula to return some other days I set to, rather than actual date of today.
First place this user defined function in a standard module:
Public Function todaz() As Date
todaz = Evaluate("=today()") + 12
End Function
Then in your worksheet, replace all instances of:
Today()
with:
todaz()
You can change the User defined function to have any date offset you wish.
When you are done testing, change all the todaz() back into Today().
Here's a non-VBA version:
Have a cell in which you put just =Today(). In the worksheet, replace all other instances of Today() with a reference to this cell. For testing, replace the Today() with whatever date you like, and when you're done, put the Today() back in.
Both this and Gary's Student's version have the advantage of being less volatile - that is, they will run much faster because Today() is one of those functions that recalculates frequently in every place it appears -- and in your case that sounds like a lot.
Sample Sheet
Profit
Sales
Expenses
COGS
Hello, I have an array of financial data that I need to turn into profit. I have been able to successfully sum all of the financial together based on a specific date range, but I have encountered a problem with cost of goods sold. Using the match function (apologies if the format is ridiculous, I am new to stackoverflow; the formula is present in the google sheet as well):
=SUM(INDIRECT("'Sales'!"&SUBSTITUTE(ADDRESS(1,MATCH($C$1,Sales!$1:$1,0),4),1,"") &MATCH(A3,Sales!A:A,0)&":"&SUBSTITUTE(ADDRESS(1,MATCH($E$1,Sales!$1:$1,0),4),1,"")&MATCH(A3,Sales!A:A,0)))+SUM(INDIRECT("'Expenses'!"&SUBSTITUTE(ADDRESS(1,MATCH($C$1,Expenses!$1:$1,0),4),1,"")&MATCH(A3,Expenses!A:A,0)&":"&SUBSTITUTE(ADDRESS(1,MATCH($E$1,Expenses!$1:$1,0),4),1,"")&MATCH(A3,Expenses!A:A,0)))+SUM(INDIRECT("'COGS'!"&SUBSTITUTE(ADDRESS(1,MATCH($C$1,COGS!$1:$1,0),4),1,"")&MATCH(A3,COGS!A:A,0)&":"&SUBSTITUTE(ADDRESS(1,MATCH($E$1,COGS!$1:$1,0),4),1,"")&MATCH(A3,Expenses!A:A,0)))
I can sum every value on every sheet by row when matching a list of IDs which is constant throughout all data sheets. My problem is: I only want to sum the cost of goods sold sheet to profit ONLY If there is a corresponding sales value in the same location but on the sales tab. Ive tried replacing the sum with sumif to no avail, as I am just getting the hang of this indirect functions. Can anyone provide me with any information that may help me better understand this problem I'd really appreciate it. Thanks
I think that the COGS was meant to be a one time expense per day. That is how all but the first example are calculated.
If so, I believe the correct answer is:
{=SUM(INDIRECT("'Sales'!"&SUBSTITUTE(ADDRESS(1,MATCH($C$1,Sales!$1:$1,0),4),1,"")&MATCH(A3,Sales!A:A,0)&":"&SUBSTITUTE(ADDRESS(1,MATCH($E$1,Sales!$1:$1,0),4),1,"")&MATCH(A3,Sales!A:A,0)))+SUM(INDIRECT("'Expenses'!"&SUBSTITUTE(ADDRESS(1,MATCH($C$1,Expenses!$1:$1,0),4),1,"")&MATCH(A3,Expenses!A:A,0)&":"&SUBSTITUTE(ADDRESS(1,MATCH($E$1,Expenses!$1:$1,0),4),1,"")&MATCH(A3,Expenses!A:A,0)))+SUMPRODUCT(IFERROR(INDIRECT("'Sales'!"&SUBSTITUTE(ADDRESS(1,MATCH($C$1,Sales!$1:$1,0),4),1,"")&MATCH(A3,Sales!A:A,0)&":"&SUBSTITUTE(ADDRESS(1,MATCH($E$1,Sales!$1:$1,0),4),1,"")&MATCH(A3,Sales!A:A,0))/INDIRECT("'Sales'!"&SUBSTITUTE(ADDRESS(1,MATCH($C$1,Sales!$1:$1,0),4),1,"")&MATCH(A3,Sales!A:A,0)&":"&SUBSTITUTE(ADDRESS(1,MATCH($E$1,Sales!$1:$1,0),4),1,"")&MATCH(A3,Sales!A:A,0)),0),INDIRECT("'COGS'!"&SUBSTITUTE(ADDRESS(1,MATCH($C$1,COGS!$1:$1,0),4),1,"")&MATCH(A3,COGS!A:A,0)&":"&SUBSTITUTE(ADDRESS(1,MATCH($E$1,COGS!$1:$1,0),4),1,"")&MATCH(A3,Expenses!A:A,0)))}
Without more info I can only come up with that.
=SUM(Sales!B2:I2)+SUM(Expenses!B2:I2)-SUMPRODUCT((Sales!B2:I2<>0)*(COGS!B2:I2))
or
=SUMPRODUCT((Sales!B2:I2)*($C$1<=Sales!B1:I1)*($E$1>=Sales!B1:I1))+SUMPRODUCT((Expenses!B2:I2)*($C$1<=Expenses!B1:I1)*($E$1>=Expenses!B1:I1))-SUMPRODUCT((Sales!B2:I2<>0)*(COGS!B2:I2)*($C$1<=COGS!B1:I1)*($E$1>=COGS!B1:I1))
if dates matters
With the sheet you provided it returns 3.2
Why did you used so much indirect & substitute?
Was it required or fixed ranged fits your need ?
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.
I was hoping someone might be able to point me in the right direction, I'm trying to automate a section of a spread sheet which shows a persons planned hours of work against the hours they actually did. The data is sourced from a worksheet which is broken down into months and departments.
Is there a way to get the reference table on the main dashboard to vlookup/index a certain column dependent on the computers date?
I.E. for May it will look in the planned and actual hours column for may and then in June it will search the June column for the same data.
Normally I would post some code but I'm not even sure where to begin on this one.
You mention VLOOKUP in you question.
To use this in VBA use, WorksheetFunction.Vlookup(), but it seems you could avoid VBA altogether if you wanted. Here are some formulas of interest:
If you want to search months by the current date, you can use this kind of vlookup (or MATCH() or HLOOKUP() if these are columns as you indicate)
=VLOOKUP(TEXT(TODAY(),"mmmm"),Range,1,FALSE)
Use "mmm" if you use 3-letter months
If months are in static column number can be taken from using the MONTH() function.
=MONTH(TODAY())
"index a certain column dependent on the computers date?"
=TODAY() gets computer's date.
I would tend to use MATCH() to get the months column (in this example I've assumed months are in row 1)
=MATCH(TEXT(TODAY(),"mmmm"),1:1,0)
You can then use INDIRECT() to match a specific month column and department row (if in a 2D format), or SUMIFS() with INDIRECT() if you want to sum hours.
As in:
=INDIRECT("'Sheet'!R" & MATCH("department_name",A:A,0) & "C" & MONTH(TODAY()), FALSE)
Thank you for all the help in regards to this problem, unfortunatly I could not quite get my head round the suggestions which have been put forward, though I have been able to solve this problem (although it is a messy solution)
=IF($F$95="March",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,2,FALSE),
IF($F$95="April",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,3,FALSE),
IF($F$95="May",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,4,FALSE),
IF($F$95="June",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,5,FALSE),
IF($F$95="July",VLOOKUP(D97,'Planned Hours'!$A$1:K37,6,FALSE),
IF($F$95="August",VLOOKUP(D97,'Planned Hours'!$A$1:K37,7,FALSE),
IF($F$95="September",VLOOKUP(D97,'Planned Hours'!$A$1:K37,8,FALSE),
IF($F$95="October",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,9,FALSE),
IF($F$95="November",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,10,FALSE),
IF($F$95="December",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,11,FALSE)))))))))))
But it works. Again thanks to all that lent a hand.
--EDIT--
By the way this is not in VBA in the end.
I am trying to create spreadsheet to use in a small retail shop.
I have a workbook which contains expenses figures on a sheet and income figure on another sheet.
We can say that the common ground between the both sheets are the month.
I would like to write a function, which will only select those expenses of a specified month.
Something like -
=SUM(IF( Table4[Month]="January", Table4[Amount]))
// I want the sum of all expenses of a given table for only
// those months which are january etc.
I tried using the above, but it failed.
Actually a more refined solution is use the build-in function sumif, this function does exactly what you need, will only sum those expenses of a specified month.
example
=SUMIF(A2:A100,"=January",B2:B100)
This should work, but there is a little trick. After you enter the formula, you need to hold down Ctrl+Shift while you press Enter. When you do, you'll see that the formula bar has curly-braces around your formula. This is called an array formula.
For example, if the Months are in cells A2:A100 and the amounts are in cells B2:B100, your formula would look like {=SUM(If(A2:A100="January",B2:B100))}. You don't actually type the curly-braces though.
You could also do something like =SUM((A2:A100="January")*B2:B100). You'd still need to use the trick to get it to work correctly.
SUMIF didn't worked for me, had to use SUMIFS.
=SUMIFS(TableAmount,TableMonth,"January")
TableAmount is the table to sum the values, TableMonth the table where we search the condition and January, of course, the condition to meet.
Hope this can help someone!