Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Week Start - Sunday instead of Monday

Is there any option in QlikView to set the week start globally to desired Day instead of default Monday.

I have tried using -1 in WeekStart but there are lot of problems.

Please check these out

LET vCYDate = Date(Today());

LET vCYWeekStart = WeekStart(vCYDate,0,-1);

LET vCYWeekNo = Week(vCYWeekStart);

LET vPYWeekDay = MakeWeekDate(Year(vCYDate)-1,vCYWeekNo, vCYWeekDay);

LET vPYWeekStart = WeekStart(vPYWeekDay,0,-1);

LET vPYWeekNo = Week(vPYWeekStart);

The main thing is I want to get the same week details for 2 given years. Try for Year 2012 and 2011 in the way I have written the code. Except first week of Jan, the result is giving the correct result. Is there a way to overcome this?

Try using WEEKNUM(<Date>) in Excel for both these dates (Jan 1st 2012 and Jan 1st 2011) as well in QlikView.

Actually the WeekStart shows Sunday but the Week number of that date is showing 1 week less than the correct week # as the vCYWeekStart / vPYWeekStart is considered as the last day of the previous week in QlikView.

How to globally set in QV to make Sunday as the start of the week and the rest of the date calculations follow it?

14 Replies
Not applicable
Author

If we use AddMonths or AddYears, it will give exactly the same date rather than the same day of previous year

For example, if today is Tuesday, 8th May 2012, I don't want 8th May 2011 which is Sunday

8th May 2012 is Week 19 and Day 3 (Sunday being the first day)

8th May 2011 is Week 20 and Day 1

So my result should be Day 3 of 19th week of 2011 (May 3rd 2011) and not the same date of 2011 (May 8th 2011)

hic
Former Employee
Former Employee

If you use the attached script, then you can calculate week number and week day so that Jan 1st always belongs to week 1 and Sunday always is the first day of the week. Then you can compare year-to-year numbers using WeekNumber and WeekDay: (Note that the difference from previous year is calculated also)

US_WeekNumber.png

Should you want to calculate the date of the previous year's corresponding date in the script, you can do this also. See attachment.

HIC

Not applicable
Author

Thanks a lot...

Not applicable
Author

2012 starts on week 2, but so far i can't figure out a fix to your code for this.

Not applicable
Author

Hello @ Henric Cronström,

This piece of code is indeed useful, but I want to know how to tweak this to suit my case.

Here the US Week 1 is Jan 1 - Jan 4 2014 - where we want to have the Dec 29th to Jan 4 2014 as Week 53 of 2013 instead.

The definition of our week is that a Week Starts Sunday and should have 7 days, in the above calendar has a week which is less than 7 days - so in case when I have to compare Week 1 of Jan 2014 to Week 2 to Jan 2014 I end up comparing 4 days to 7 days.

Any thoughts ?

Thanks,

Lav