Weeks Calculation for Adventureworks Time Dimension
The following Named Calculated filed returns Week Start Date & End Date.
'Week ' + Convert(Char(2), WeekNumberOfYear) + '(' +
Convert(Char(10),(FullDateAlternateKey - (DATEPART(dw,FullDateAlternateKey)-1)),101) + ' - ' +
Convert(Char(10),(FullDateAlternateKey - (DATEPART(dw,FullDateAlternateKey) - 1) + 6),101) + ')'
Examples:
-- for Date '2008-01-01', Returns Week 1(01/01/2008 - 01/07/2008)
-- for Date '2008-09-08', Returns Week 37(09/07/2008 - 09/13/2008)
ExcelSheet Formulas for Week Calculation:
Date Cell(A2): 09/08/2008
Week Start Date Cell(K2): =DATE(YEAR(A2), MONTH(A2), DAY(A2) - (WEEKDAY(A2) - 1))
-- Returns 09/07/2008
Week End Date Cell(L2): =DATE(YEAR(A2), MONTH(A2), DAY(A2) - (WEEKDAY(A2) - 1) + 6)
--Returns 09/13/2008
Start & End Date: =CONCATENATE(YEAR(A2), " - Week ", WEEKNUM(A2), " (", TEXT(K2, "mm/dd/yyyy"), " - ", TEXT(L2, "mm/dd/yyyy"), ")")
-- Returns Week 37(09/07/2008 - 09/13/2008)
Quarter Calcualtion:
=TEXT(A2,"yyyy") & " - " &"Q"&INT(((MONTH(A2))-1)/3)+1
-- Returns 2008 - Q3
'Week ' + Convert(Char(2), WeekNumberOfYear) + '(' +
Convert(Char(10),(FullDateAlternateKey - (DATEPART(dw,FullDateAlternateKey)-1)),101) + ' - ' +
Convert(Char(10),(FullDateAlternateKey - (DATEPART(dw,FullDateAlternateKey) - 1) + 6),101) + ')'
Examples:
-- for Date '2008-01-01', Returns Week 1(01/01/2008 - 01/07/2008)
-- for Date '2008-09-08', Returns Week 37(09/07/2008 - 09/13/2008)
ExcelSheet Formulas for Week Calculation:
Date Cell(A2): 09/08/2008
Week Start Date Cell(K2): =DATE(YEAR(A2), MONTH(A2), DAY(A2) - (WEEKDAY(A2) - 1))
-- Returns 09/07/2008
Week End Date Cell(L2): =DATE(YEAR(A2), MONTH(A2), DAY(A2) - (WEEKDAY(A2) - 1) + 6)
--Returns 09/13/2008
Start & End Date: =CONCATENATE(YEAR(A2), " - Week ", WEEKNUM(A2), " (", TEXT(K2, "mm/dd/yyyy"), " - ", TEXT(L2, "mm/dd/yyyy"), ")")
-- Returns Week 37(09/07/2008 - 09/13/2008)
Quarter Calcualtion:
=TEXT(A2,"yyyy") & " - " &"Q"&INT(((MONTH(A2))-1)/3)+1
-- Returns 2008 - Q3
Comments