Calculate the week number of a given date using a given a reference year - excel

I have a formula which calculates the week number of a given date:
=WEEKNUM(Sheet2!N83)
I want a formula which returns the week number using 2018 as reference, in a similar manner as the above formula does. If the year is 2019, I want it to return weeknum + 52, so for 2019-01-01 I get week number '53'.
How can I achieve this?

This is only valid for years 2018 and 2019:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(Sheet2!N83)+52)
or:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(DATE(2018,MONTH(Sheet2!N83),DAY(Sheet2!N83)))+52)

You actually need a formula which calculates the difference in weeks.
In A1 cell, fill the first day of the reference year (e.g. 2018-01-01).
In A2 cell, put the day of the week of your interest (e.g. 2019-01-03).
In the A3 cell, use this formula to calculate the difference in weeks (in case your week begins at Mondays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-2), B2, "d") / 7), 0) + 1
Or this one (in case your week begins at Sundays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-1), B2, "d") / 7), 0) + 1

Related

Formula based on first monday or tuesday etc of the week

Is there a way to put a year into a cell (say A1), then the day of the week you want (say Monday in cell A2) and enter into the 12 cells below it the first monday of each month (or first tuesday, etc, based on whats in cell A2)?
I have been able to figure out how to do it with 1 day but I would like it to be interactive.
=DATE(2022,{1;2;3;4;5;6;7;8;9;10;11;12},7-WEEKDAY(DATE(2022,{1;2;3;4;5;6;7;8;9;10;11;12},1)-5,3))
With Office 365:
=LET(yr,A1,
wkdy,MATCH(PROPER(A2),{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),
mnt,SEQUENCE(12),
DATE(yr,mnt,1)+MOD(8-WEEKDAY(DATE(yr,mnt,1),10+wkdy),7))
You where pretty close with your formula
=DATE(A1,{1;2;3;4;5;6;7;8;9;10;11;12},7)-WEEKDAY(DATE(A1,{1;2;3;4;5;6;7;8;9;10;11;12},7),A2)
Where
A1 = year string
A2 = day of the week as number (1 = Saturday, 2 = Sunday, etc.)

excel formula for previous quarters

I am looking for a formula to pull up the previous quarter and year like in the Column J, for the Oct 20, it should return Q3 20 instead of Q4 20.
Currently my formula only returns the correct quarter but I would need the previous to last quarter and year?
To return the quarter | year corresponding to 3 months ago, i.e. :
"previous quarter & year"
simply replace col H date references with edate(date,-3). Cell J17 formula to enter is then:
="Q"&ROUNDUP(MONTH(EDATE(H17,-3))/3,0)&" "&YEAR(EDATE(H17,-3))
If you have Office 365 compatible version of Excel, you could shorten (albeit ever so slightly in this case) with the let function as so:
=LET(x,EDATE(H17,-3),"Q"&ROUNDUP(MONTH(x)/3,0)&" "&YEAR(x))

Automatically change excel cell value depending on current Month

Stock analysis Dashboard. I need to compare the stock from today vs the previous 6 months.
My stock data
Cell A1:R1 - month data example Cell A1= June 2017, B1= 7/2017 ....till R1= December 2018.
Cell A2:R2 Stock numbers data example A2=23, B2=25,........till R2=50.
IF I want to see the stock today month which is July 2018= M1 vs six months February 2018 H2 and the stock level calculation will which is M2=26 - H2= 30 =-4.
But instead of entering formula every time I need to be updated every month based on the today month?
Any tips on how to do it?
Thanks
I also miss a date...
If you use today() function to identify today's date you can use:
=HLOOKUP(TODAY(),$A$1:$S$2,2)-HLOOKUP(DATE(YEAR(TODAY()),MONTH(TODAY())-5,1),$A$1:$S$2,2)
If you need a cell with a specific date, replace today() formula with that cell.
I find the question a bit confusing. If A1 is June 2017, I am missing a month if R1 is December 2018 and July 2017 is in M1. Also, even though you said 6 months, I am assuming that you want 5 months so that July compares to February.
This response assumes that A1 is wrong but R1 and M1 (and B1 through R1 are accurate) and that the values in A1 through R1 are actually an Excel date that is formatted as m/yyyy (as opposed to some text representation of a date).
This formula is further complicated since I do not know what day is used in the date representation in A1 through R1, hence I am adapting both that date and the current date to be a fixed day of the month (I chose the first day of the month in my formula).
Here is the formula that computes the -4 assuming M1 is 7/2018, M2 is 26, H1 is 2/2018, H2 is 30 and we want to compare column M to column H since today is in July and we want to compare July to February (5 months difference):
=INDIRECT("R2C"&MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0),FALSE)-INDIRECT("R2C"&MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0)-5,FALSE)
This is an array function so it needs to be entered with [Ctrl]+[Shift]+[Enter].
The way it works is that it computes from today's date, the date value equal to the first day of this month. Then it compares that against the range A1:R1 with each of those dates likewise moved to the first of the month. This gives us the column to use for "this month" and using the same computation but subtracting 5 gives us the column to use for "six months ago." Out of sheer laziness I used these values in an indirect cell reference to pull the Row 2 values for "this month" and "six months ago" and subtracted the latter from the former (i.e., "this month" - "six months ago").
In other words, this part of the formula gives me the column of the current month:
MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0)
and this part gives me the column of the month six months ago (as defined in the original post):
MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0)-5
As I indicated, this may not be what you wanted, but this is what I thought you were asking.
Alternate version using INDEX function
=INDEX(A2:R2,MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0))-INDEX(A2:R2,MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0)-5)
The above would also be entered as an array formula.

How to calculate the number of weeks between 2 date range in excel

I have a question here, I have 3 columns in excel, A1 is being the calendar date; column B1 has the fiscal_quarter_start_date ; and fiscal_quarter_end_date in column C1.
I am trying to find the number of week falling in between the A2 and A3. The issue here is I should consider the first sunday as the first week of the quarter. My fiscal year starts on Feb of every month.
The reason I am doing this calculation is to populate the count of weeks numbers of a quarter, where my first week starts from the first sunday of the quarter.
=ROUNDUP(MOD(IF(A13>=IF(DATE(YEAR($A13),2,1)=1,DATE(YEAR($A13),2,1),DATE(YEAR(A13),2,7-WEEKDAY(DATE(YEAR(A13),2,1),1)+2)),ROUNDUP((A13-IF(WEEKDAY(DATE(YEAR(A13),2,1),1)=1,DATE(YEAR($A13),2,1),DATE(YEAR($A13),2,7-WEEKDAY(DATE(YEAR($A13),2,1),1)+2))+1)/7,0),ROUNDUP((A13-IF(DATE(YEAR($A13)-1,2,1)=1,DATE(YEAR($A13)-1,2,1),DATE(YEAR($A13)-1,2,7-WEEKDAY(DATE(YEAR($A13)-1,2,1),1)+2))+1)/7,0)),13.01),0)
above is the formula i've got all the way. However rounding up with 13 is not a viable solution as its not necessary that it should have always have 13 weeks all the time.
For example: 5/1/16 should be week 1 As it is a begging of a q2 and 5/1/16 is the starting on Sunday. In this case using above formula result for the week is 13
Please help me..
You can use WEEKNUM to get the week number.
However you mentioned that your week wont end at the Saturday, but at the Sunday, so you have to do =WEEKNUM(<insert here where the date is>,2)
=WEEKNUM (serial_num, [return_type])
serial_num - A valid Excel date in serial number format.
return_type - [optional] The day the week begins. Default is 1.
Return_type can either be 1 or 2:
1 - Week begins on Sunday
2 - Week begins on Monday
or... read it here for counting weeks between 2 dates.
Enter this formula =(A2-A1)/7 into a blank cell, (A2 indicates the end date and A1 is the start date)
If you just want to get the whole weeks, please apply this INT function: =INT((A2-A1)/7)
Try it here, on sheet "week"
Hope it'll help.
Assuming that the Quarter start and end dates are in A3:A6 respectively then:
=IF(AND(C1>=$A3,C1<$A4),WEEKNUM(C1)-WEEKNUM($A3)+1,IF(AND(C1>=$A4,C1<$A5),WEEKNUM(C1)-WEEKNUM($A4)+1,IF(AND(C1>=$A5,C1<$A6),WEEKNUM(C1)-WEEKNUM($A5)+1,WEEKNUM(C1)-WEEKNUM($A6)+(IF(AND(C1>=DATE(YEAR(C1),1,1),C1<DATE(YEAR(C1),MONTH($A6),DAY($A6))),53,1)))))
This is checking whether the date in the cell above (C1) is between the quarter start and end dates, and checking the difference in weeks from the start date. To cover the anomoly for Q4 extending into the next year, the IF statement at the end adds 53 instead of 1 for the affected dates.
Edit #1
=WEEKNUM(A1)-WEEKNUM(B1)+IF(AND(A1>=DATE(YEAR(A1),1,1),A1<DATE(YEAR(A1),MONTH(B1),DAY(B1))),53,1)
This works for the A1:C1 format you mentioned in your comment. Obviously this relies on B1 and C1 being updated manually.
Edit #2
=WEEKNUM(C1)-WEEKNUM(B1)
If you are counting 05/01/2016 as week 1 then add 1 to the result. Take off the highest week number (default is counting from sunday or you can change to (C1,1) if you want to define it exactly) from the lowest week number. Reult is 13 which would match the manual calculation.
You will want to look at the previous edit for an example of the if formula you will need when the quarter ends in another year. to reverse the negative figure it will need to add 52 when the date is in the early part of the next year and 0 when it is not.
You can use the "hidden" function DATEDIF:
For example in A1 we write start date (01/05/2016), in B1 - end date (31/07/2016) and in C1 = DATEDIF(A1,B1,"d")/7 the result will be 13

weekly spend formula in Excel 2007

Can anyone help please?
I have a spreadsheet where A:A contains dates and B:B shows the amount i spent on that day in relation to the date in A:A.
What i would like to do is have C1 show a running total of what i have spent this week.
I am using Excel 2007 and i cannot get my head around this.
I am going round in circles here, i can get =SUMPRODUCT((WEEKDAY(A2:A1000)=5)*(B2:B1000)) which shows how much has been spent on a thursday, justcannot work out how to say for the last week
You can apply the SUMIFS function with the TODAY functio and WEEKDAY function to gain a total of the current week.
'for a Sunday to Saturday week
=SUMIFS(B:B, A:A, ">"&TODAY()-WEEKDAY(TODAY()))
'for a Monnday to Sunday week
=SUMIFS(B:B, A:A, ">"&TODAY()-WEEKDAY(TODAY(), 2))
'for the previous Sunday to Saturday week
=SUMIFS(B:B,A:A, ">"&TODAY()-WEEKDAY(TODAY())-7,A:A, "<="&TODAY()-WEEKDAY(TODAY()))
=SUMIFS(B:B, A:A, ">"&TODAY()-WEEKDAY(TODAY(), 2)-7,A:A, "<="&TODAY()-WEEKDAY(TODAY(), 2))
The total for other 7 day periods can be returned with a little maths.
I've used the SUMIFS function here as the syntax changes between the SUMIF function and SUMIFS. Using SUMIFS in all cases means that you do not have to alter the syntax depending on whether you are using it one condition or multiple conditions.
Make it simpler.
Add a column before the DATE column and call it WEEK
In A2 use (x should be 1 , 2 depending on the system for your country)
=Year(B2)&WeekNum(B2,x)
1 = week start sunday
2 = week start monday
then in D2 use ( and drag it down the column)
=SUMIF(A$2:A2,A2,C$2:C2)

Resources