My problem is the following...
I have a little aeroplane and I need to track the hours. I have to track the hours by sectors and not the total of the day (that's why sometimes I have 2 or 3 on the same day).
Now this is the problem... On column C I need to SUM the hours of the last 7 days. And any given 7 days, not just last week. To do it manually is quite easy... the problem is that I need a formula as my records are quite large...
Here with a small example (let's say that there was NO HOURS before 15/01/2009)...
COLUMN A-------COLUMN B-------COLUMN C
DATE--------------HOURS-------HOURS LAST 7 DAYS
15/01/2009-------01:00-------01:00
15/01/2009-------02:15-------03:15
16/01/2009-------01:15-------04:30
17/01/2009-------01:30-------06:00
18/01/2009-------01:30-------07:30
18/01/2009-------01:00-------08:30
18/01/2009-------02:00-------10:30
19/01/2009-------02:30-------13:00
19/01/2009-------03:00-------16:00
20/01/2009-------////////--------16:00
21/01/2009-------01:00-------17:00
22/01/2009-------01:30-------15:15
23/01/2009-------02:00-------16:00
I've been fighting for the last weeks trying to figure out a formula but no luck... any suggestions?
Thanks
Another solution that basically does much the same as the earlier offered solutions:
In C1, enter the following formula:
{=SUM(IF(($A$1:$A1>=($A1-6))*($A$1:$A1<=$A1), $B$1:$B1, 0))}
And then just drag the formula down.
If you're not familiar with array formulas, the {} outer brackets just indicate that the formula is an array formula. To get it to execute correctly, you need to copy the part inside the {} brackets into the formula bar, and then hit Ctrl+Shift+Enter to indicate that it's an array formula.
First thing is to get the begin date, which would be the following function:
=Now() - 7
If you renamed that cell to "WeekBegin", then you could use the following formula to calculate the total hours:
=SUMIF(A:A,">=" & WeekBegin,B:B)
Notice that I used column references; this was to both simplify the formula, but also allow you to add new data to the end of the range easily. You will need to take care that your WeekBegin cell is not in that column A or column B, otherwise you'll get a circular reference warning.
If you planned to have numeric data above or below your input range, you would need to explicitly call out the sum and criteria ranges as follows:
=SUMIF(A2:A14,">=" & WeekBegin,B2:B14)
Additionally, you may find that your result comes up initially as a decimal. That's Excel's date serial format, so you may need to format your result as time.
Hope that helps!
[Edit: On second pass, if you're looking to sum a range based on a from and to date (so any 7 days as you seem to imply in your post), look for the previous poster's note, i.e.:
=SUM(B:B) - SUMIF(A:A, "<="& BeginDate, B:B) - SUMIF(A:A, ">"& EndDate, B:B)
A more elegant solution is offered in Excel 2007 using the SumIFS() function:
=SUMIFS(B:B, A:A, ">=" & FromDate,A:A, "<" & ToDate)
Note that the arguments for SUMIFS are in a different order than the standard SUMIF.
Happy Summing!]
Here's the data in better format if someone wants to try:
15-Jan-2009 01:00
15-Jan-2009 02:15
16-Jan-2009 01:15
17-Jan-2009 01:30
18-Jan-2009 01:30
18-Jan-2009 01:10
18-Jan-2009 02:00
19-Jan-2009 02:30
19-Jan-2009 03:00
20-Jan-2009
21-Jan-2009 01:00
22-Jan-2009 01:30
23-Jan-2009 02:00
I got the function:
=SUM($B$1:$B$13)-SUMIF($A$1:$A$13, "<="& (A1- 7), $B$1:$B$13) - SUMIF($A$1:$A$13, ">"& (A1), $B$1:$B$13)
This was based on Sum of named ranges conditional to date?.
The idea is to first compute the total sum: SUM($B$1:$B$13)
then subtract any values that happened older than 7 days ago: SUMIF($A$1:$A$13, "<="& (A1- 7), $B$1:$B$13)
then subtract any values that happened in the future: SUMIF($A$1:$A$13, ">"& (A1), $B$1:$B$13)
The point is to use SUMIF function, which "adds the cells specified by a given criteria."
Related
Note: I am putting this question as Excel and Google Docs as they have a ton of overlap for simple questions like this.
I have two columns of data. A date of a purchase and how much that purchase was for.
A B
11/23/2015 $59
12/5/2015 $23.32
1/21/2016 $12.09
1/22/2016 $78.21
1/22/2016 $5.88
2/14/2016 $0.13
... ...
(thousands of rows below this)
I want to SUM the amount of money spent on Mondays, Tuesdays, Wednesdays, etc.
If I use SUMIF, I run into this problem:
=SUMIF(A:A, WEEKDAY(A:A), B:B)
^ WEEKDAY only takes in a single date value.
I do not want a function that I have to drag downwards.
How would I accomplish this?
Try this query function:
=QUERY({A:B},"select dayOfWeek(Col1), sum(Col2) where Col1 is not null group by dayOfWeek(Col1)")
In this formula I used Array {A:B} and notation Col1, Col2... in the formula because now when you add new columns, the formula won't fail.
And the similiar formula, using sumif:
={arrayformula(unique(weekday(A:A))),arrayformula(sumif(weekday(A:A),unique(weekday(A:A)),B:B))}
In Excel you do it with this Array formula. Array formula needs to be entered with Ctrl-Shift-Enter.
{=SUM(IF(WEEKDAY($A$2:$A$1000,1)=E2,$B$2:$B$1000,0))}
This assumes your day of week in number is E2. The second parameter in Weekday function defines how you number the days of Week. Here I have used 1 which means 1 = Sunday and 7 = Saturday
I am using this formula to determine if the date is column F occurs after the date in column G, but before the date in column G + 3 work days.
I was using the following formula which worked quite well:
=SUMPRODUCT(($F$5:$F$1000>$G$5:$G$1000)*($F$5:$F$1000<($G$5:$G$1000+3)))
But I realized I was not accounting for weekends in the final "+3."
So I tried this:
=SUMPRODUCT(($F$5:$F$1000>$G$5:$G$1000)*($F$5:$F$1000<(WORKDAY($G$5:$G$1000,3))))
And it returns #VALUE! This happens whether I push Ctrl+Shift+Enter or not.
How do I make this work please?
As appointed by #Tim, the workday function cannot accept a range. But you can simulate what you need with the weekday function by using this:
If(weekday(G2:G5; x)>=y;5;3)
Where x is your code of sunday, y is Wednesday. If your working day is greater than wednesday, then you will sum 5, not 3.
=SUM(IF($F$2:$F$3 > $G$2:$G$3; 1; 0)*
IF($F$2:$F$3 < $G$5:$G$1000 + IF(WEEKDAY($G$2:$G$3)>= Y ;5;3); 1; 0))
Weekday does accept a range, and it returns a range of weekdays. When you compute if (that also accepts a range) you create an 0/1 matrix (which is like your
indicator matrix of rows where the condition is active). If you * both matrix of conditions, you will have the remaining rows that matches both conditions. And lastly, if you apply the sum, you will get the count.
This is a way to simulate sumproduct when you have conditions that requires a formula
You will have to use ctrl +shift + enter.
03/09/2015 02/09/2015
07/09/2015 03/09/2015
Using this dates i obtained the result of 2.
Which is correct, both dates are greater than their partners but lower than their partners + 3 working days
P.S: I use spanish Excel, so it can be mistakes of formula translating
Lori_m, in the comments to my question provided a working answer:
Try inserting a + sign into the formula to convert the range to an array: WORKDAY(+$G$5:$G$1000,3) – lori_m 17 hours ago
Thanks.
The Start_Date argument of the WORKDAY function cannot accept a range (eg $G$5:$G$1000 in your code). I'm not exactly sure what your trying to do without more details and some sample data, so that's the best help I can give you.
I am trying to create a formula in Excel that will count cells with 3 certain criteria. My example is below: cell M3:M350 is the name, cell Q3:Q350 is the date, cell R3:R350 is the current step. I need to know how many times the name Amanda shows up that is in the current step of Material Review, and that is also 30 days or less than the date in cell Q3:Q350. The formula I have been trying is:
=COUNTIFS('Active Projects'!M3:M350,"AMANDA MARTIN",'Active
Projects'!Q3:Q350,"<="&NOW+30,'Active Projects'!R3:R350,"*MATERIAL REVIEW")
The answer keeps giving me 0, and it should be 1.
Does anybody know the correct formula to use? It has been eating at me for a week now, and I have tried different variations, and still cannot get it to not count the dates older than 30 days from today.
please update your formula as follows:
=COUNTIFS('Active Projects'!M3:M350,"AMANDA MARTIN",'Active Projects'!Q3:Q350,"<=" & TODAY() + 30,'Active Projects'!R3:R350,"*MATERIAL REVIEW")
Structure you have used for date is not correct:
=COUNTIFS('Active Projects'!M3:M350,"AMANDA MARTIN",**'Active
Projects'!Q3:Q350,"<="&NOW+30**,'Active Projects'!R3:R350,"*MATERIAL REVIEW")
there should be brackets () after NOW or TODAY functions.
I have an Excel 2010 workbook with this formula:
=EOMONTH("01"&TEXT(B7,"MMM")&IF(MONTH(CMVAR)<4,TEXT(YEAR(CMVAR)-1,"YYYY"),TEXT(YEAR(CMVAR),"YYYY")),0)
It resolves when you are in the cell and press Enter, however when the workbook first opens or is refreshed, the result is #VALUE!. Here are the components:
B7 =IF(OR(MONTH(CMVAR)>6,MONTH(CMVAR)<4),"Apr",IF(MONTH(CMVAR)=4,TEXT(EDATE(CMVAR,-3),"MMM"),IF(MONTH(CMVAR)=5,TEXT(EDATE(CMVAR,-3),"MMM"),TEXT(EDATE(CMVAR,-3),"MMM"))))
which equates to Apr.
CMVAR 31/03/2015
The formula is being used because in April, May, June (first three fiscal periods) we require comparison data to show in the 12-period grid from the previous financial year. From July onwards we will have comparable data from the current year and so the grid can start from April. Once the month has been determined I'm trying to work out what the date of the end of that period is, taking into account that Jan, Feb and Mar are actually periods 10, 11 and 12 of the fiscal year and so the year element of the formula will be the prior year if CMVAR shows the date to be in any of those months.
Is there a better way that avoids the error or a way to fix it?
It is not completely clear what result do you expect for different values of CMVAR, but looking at your formula, I suppose you want it to be:
You can calculate Result with the following formula:
=EOMONTH(CMVAR,-MAX(MOD(MONTH(CMVAR)-4,12),3))
If the picture above does not show your expected output, can you please prepare similar table?
EDIT:
To explain how the problem is solved, I have created additional columns with intermediate calculations:
column C is the month difference between CMVAR and expected result - the goal is to find a formula returning this number
column D calculates month of CMVAR
column E - function MOD returns the remainder after number is divided by divisor (12).
column E matches all values of C, except 0,1,2, so in column F function MAX replaces those values with 3
Your EOMONTH formula is going wrong because the TEXT part should be in the form TEXT(date,"YYYY"). YEAR(CMVAR) gives a number rather than a date.
You could use instead
=EOMONTH("01"&TEXT(B7,"MMM")&IF(MONTH(CMVAR)<4,TEXT(EDATE(CMVAR,-12),"YYYY"),TEXT(CMVAR"YYYY")),0)
or this may be easier than using the TEXT functions
=EOMONTH("01"&B7&IF(MONTH(CMVAR)<4,YEAR(CMVAR)-1,YEAR(CMVAR)),0)
Your B7 formula is OK but could be simplified to
=IF(OR(MONTH(CMVAR)>6,MONTH(CMVAR)<4),"Apr",TEXT(EDATE(CMVAR,-3),"MMM"))
The following formula doesn't work:
=SUMIFS(JOBS_NUMBER,JOB_TYPE,$A10,MONTH_CLAIMED,(AND(OR(">"&$H$7,"="& $H$7), OR("<"&$J$7,"=" &$J$7))),SECTOR, "=Residential")
I'm trying to sum the number of jobs:
if the range JOB_TYPE matches,
if the MONTH_CLAIMED is greater than or equal to H7 (which contains the start of the fiscal year) AND less than or equal to J7 (which is the end of the fiscal year), and
the SECTOR must be Residential.
The embedded And(OR(inequalities are the problem, since the following test formula returns 0:
=SUMIF(Z8, AND(OR(">"&$H$7,"="&$H$7),OR("<"&$J$7,"="&$J$7)),Y8)
where Z8 is a date between H7 and J7, and Y8 is 1.
I'd appreciate help with correcting the syntax or possible alternatives to accomplish the same task.
Assuming,the required Job Type is in A10, and you wish to sum relevant values in ColumnY rows 7 to 12 inclusive, this may help:
=SUMIFS(Y7:Y12,JOB_TYPE,A10,Z7:Z12,">="&H7,Z7:Z12,"<="&J7,Sector,"Residential")
However the above does assume compatibility between MONTH_CLAIMED and dates elsewhere.
You should use:
=sumifs(Y8, Z8, ">="&$H$7, Z8, "<="&$J$7)
No need for the AND / OR
Hope this helps