Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Paulexter
Contributor II
Contributor II

MakeWeekDate is off by 2 weeks

First off, here are my environment variables for weeks:

SET FirstWeekDay=6;
SET BrokenWeeks=0;

This statement evaluates to '2', which is what I would expect:

week('2022-01-02')

With weeks starting Sunday, Jan 2nd was the start of the second week of the year. Now, if I feed this result into MakeWeekDate, like this:

MakeWeekDate(2022,2,6)

It returns 1/16/2022 - it's off by 2 full weeks! I'm assuming what's going on is that the MakeWeekDate function does not pay attention to the environment variables, but I'm not positive. But my desired behavior would be for MakeWeekDate(2022,2,6) to know that week 2 started on Jan 2nd, and it should return the date of Sunday of that week, which is Jan 2nd.

Is there any way to get that behavior? I'm trying to think of a good kludge to get the job done...

Just to expand on my use case - I'm using Google Analytics data, which uses Sun-Sat weeks that are not broken. Google Analytics weeks look like this: '202202', with that representing Jan 2nd-8th, but I can't get Qlik to properly convert it into a date. 

Labels (1)
1 Solution

Accepted Solutions
Paulexter
Contributor II
Contributor II
Author

This seems to work around the issue:

=date(MakeWeekDate(year(v1),week(v1),6)-if(weekday(year(v1)&'-01-01')>3,14,7))

v1 = any Sunday of the year. We subtract 14 days for years where January 1st is Thurs-Sat, and we subtract 7 days for years where Jan 1st is Sun-Wed. 

If there is a cleaner solution, I'd be happy to hear it!

View solution in original post

1 Reply
Paulexter
Contributor II
Contributor II
Author

This seems to work around the issue:

=date(MakeWeekDate(year(v1),week(v1),6)-if(weekday(year(v1)&'-01-01')>3,14,7))

v1 = any Sunday of the year. We subtract 14 days for years where January 1st is Thurs-Sat, and we subtract 7 days for years where Jan 1st is Sun-Wed. 

If there is a cleaner solution, I'd be happy to hear it!