Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
alvinford
Contributor III
Contributor III

How to Create Week

Hi ,

Request your help to achieve this...

I have the following Data.

YearCityStartDateEndDate
2013AZ2/8/201415/8/2014
2013CA12/10/20131/11/2013
2013AX9/8/201322/8/2013

Would like to derive the Weeks between StartDate and End Date. The First 7 Days between StartDate and EndDate will be considered as Week1 and Next 7 Days will be Week 2 and So on for each City. The Final Output will be as below.


I have highlighted the City and Week for better understanding indicating every City has Week1 and so on..


Thank You in Advance...


Start DateEnd DateDateYearCityWeek
12/10/201320/12/201312/10/20132013CAWeek1
12/10/201320/12/201313/10/20132013CAWeek1
12/10/201320/12/201314/10/20132013CAWeek1
12/10/201320/12/201315/10/20132013CAWeek1
12/10/201320/12/201316/10/20132013CAWeek1
12/10/201320/12/201317/10/20132013CAWeek1
12/10/201320/12/201318/10/20132013CAWeek1
12/10/201320/12/201319/10/20132013CAWeek2
12/10/201320/12/201320/10/20132013CAWeek2
12/10/201320/12/201321/10/20132013CAWeek2
12/10/201320/12/201322/10/20132013CAWeek2
12/10/201320/12/201323/10/20132013CAWeek2
12/10/201320/12/201324/10/20132013CAWeek2
12/10/201320/12/201325/10/20132013CAWeek2
12/10/201320/12/201326/10/20132013CAWeek3
12/10/201320/12/201327/10/20132013CAWeek3
12/10/201320/12/201328/10/20132013CAWeek3
12/10/201320/12/201329/10/20132013CAWeek3
12/10/201320/12/201330/10/20132013CAWeek3
12/10/201320/12/201331/10/20132013CAWeek3
12/10/201320/12/201301/11/20132013CAWeek3
02/08/201415/08/201402/08/20142013AZWeek1
02/08/201415/08/201403/08/20142013AZWeek1
02/08/201415/08/201404/08/20142013AZWeek1
02/08/201415/08/201405/08/20142013AZWeek1
02/08/201415/08/201406/08/20142013AZWeek1
02/08/201415/08/201407/08/20142013AZWeek1
02/08/201415/08/201408/08/20142013AZWeek1
02/08/201415/08/201409/08/20142013AZWeek2
02/08/201415/08/201410/08/20142013AZWeek2
02/08/201415/08/201411/08/20142013AZWeek2
02/08/201415/08/201412/08/20142013AZWeek2
02/08/201415/08/201413/08/20142013AZWeek2
02/08/201415/08/201414/08/20142013AZWeek2
02/08/201415/08/201415/08/20142013AZWeek2
09/08/201410/10/201409/08/20142014AXWeek1
09/08/201410/10/201410/08/20142014AXWeek1
09/08/201410/10/201411/08/20142014AXWeek1
09/08/201410/10/201412/08/20142014AXWeek1
09/08/201410/10/201413/08/20142014AXWeek1
09/08/201410/10/201414/08/20142014AXWeek1
09/08/201410/10/201415/08/20142014AXWeek1
09/08/201410/10/201416/08/20142014AXWeek2
09/08/201410/10/201417/08/20142014AXWeek2
09/08/201410/10/201418/08/20142014AXWeek2
09/08/201410/10/201419/08/20142014AXWeek2
09/08/201410/10/201420/08/20142014AXWeek2
09/08/201410/10/201421/08/20142014AXWeek2
09/08/201410/10/201422/08/20142014AXWeek2


Regards,

Alvin.

1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

You can use the method described in Creating Reference Dates for Intervals.

Load Year, City, StartDate, EndDate

          Div( IterNo() + 6, 7 ) as ReferenceWeek,

          Date( StartDate + IterNo() – 1 ) as ReferenceDate

          From SourceTable

          While IterNo() <= EndDate - StartDate + 1 ;

HIC

View solution in original post

2 Replies
hic
Former Employee
Former Employee

You can use the method described in Creating Reference Dates for Intervals.

Load Year, City, StartDate, EndDate

          Div( IterNo() + 6, 7 ) as ReferenceWeek,

          Date( StartDate + IterNo() – 1 ) as ReferenceDate

          From SourceTable

          While IterNo() <= EndDate - StartDate + 1 ;

HIC

jmmayoral3
Creator
Creator

Try this.

Dates:

LOAD * INLINE [

Year, City, StartDate, EndDate

2013, AZ, 2/8/2014, 15/8/2014

2013, CA, 12/10/2013, 1/11/2013

2014, AX, 9/8/2014, 22/8/2014

];

NOCONCATENATE

Temp1:

LOAD

     *,

     date(StartDate + IterNo()-1,'DD/MM/YYYY') as Tdate,

     'Week '&ceil(interval(date(StartDate + IterNo())-StartDate,'D')/7) as Week  

RESIDENT Dates

WHILE date(StartDate + IterNo()) <= date(EndDate+1)

;