Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Week of the month

Hi,

I wanted to create another field which is will define as number of the Week for the Date.  The number of the week should will start from 1 and will end with 4 or 5 for the particular month.  Please let me know the expression.

Week NumberRangeDate
11 - 6 Nov 2011
27 - 13 Nov 2011
314 - 20 Nov 2011
421 - 27 Nov 2011
528 - 30 Nov 2011
11 - 4 Dec 2011
25 - 11 Dec 2011
312 - 18 Dec 2011
419 - 25 Dec 2011
526 - 31 Dec 2011


1 Solution

Accepted Solutions
swuehl
MVP
MVP

Try something like

LOAD *

,if(month(weekend(Date))= month(Date),div(WeekendDay,7),div(day(Weekend(Date,-1)),7)+1)+1 as Weeknumber

;

LOAD *

,day(WeekEnd(Date)) as WeekendDay

,day(Date) as DayOfMonth

,weekday(Date) as Weekday

;

LOAD

date(makedate(2011,1,1)+recno()-1) as Date

AUTOGENERATE 365

;

View solution in original post

4 Replies
syed_muzammil
Partner - Creator II
Partner - Creator II

swuehl
MVP
MVP

Try something like

LOAD *

,if(month(weekend(Date))= month(Date),div(WeekendDay,7),div(day(Weekend(Date,-1)),7)+1)+1 as Weeknumber

;

LOAD *

,day(WeekEnd(Date)) as WeekendDay

,day(Date) as DayOfMonth

,weekday(Date) as Weekday

;

LOAD

date(makedate(2011,1,1)+recno()-1) as Date

AUTOGENERATE 365

;

sakthi266
Contributor III
Contributor III

Hi,  

         In that case if Weekend is 07th date of everymonth. Then it will shows 01st to 6th date as 2nd week which is wrong. It should show 1st week. Please help on this. 

Example : May Month Weekstart from 01-May-2011 and ends on 07-May-2011. So this is weekno 1 and 08-May-2011 to 14-May-2011 is 2nd week but here it is showing wrong. Please check and revert

Regards, 

Sakthivel.S

sakthi266
Contributor III
Contributor III

Hi 

  This Works fine.

 

if((week(Date) - week(monthstart(Date)) + 1)<1,1,(week(Date) - week(monthstart(Date)) + 1))

Regards, 

Sakthivel.S