Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
ananyaghosh
Creator III
Creator III

how to calculate the week number from a date?

Hi,

I am using the below code to calculate previous week number based on current date:

Let vPreviousWeekID = replace(weekname(today(),-1),'/','-W');

trace 'Previous WeekID = ' & $(vPreviousWeekID);


and it gives me this results:


Previous WeekID = & 2017-W15


which is incorrect and it should be: Previous WeekID = & 2017-W17

please give me a suggestion that what is wrong here?

Thanks,

Sandip Ghosh

15 Replies
swuehl
MVP
MVP

a) Please define the week numbering you want to use.

b) Please post a small sample QVW with your currently used script.

ananyaghosh
Creator III
Creator III
Author

hi,

One correction :

in Qlikview 12.1 I got:  2017/17 using the expression like this : weekname(today(1))

but in Qliksense 3.1 I have used the same expression, but I got : 2017/16

But, I don't know the why it is happening.

Thanks,

Sandip

ananyaghosh
Creator III
Creator III
Author

hi,

One correction :

in Qlikview 12.1 I got:  2017/17 using the expression like this : weekname(today(1))

but in Qliksense 3.1 I have used the same expression, but I got : 2017/16

But, I don't know the why it is happening.

Also in my Qliksense app the below variables are defined:

SET FirstWeekDay=6;

SET BrokenWeeks=1;

SET ReferenceDay=0;

SET FirstMonthOfYear=1;

But I don't know the impact of the variables here.

Thanks,

Sandip

Anil_Babu_Samineni

I am using this for Qlik Sense

Capture.PNG

I got like below, What is your issue

Capture.PNG

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
ananyaghosh
Creator III
Creator III
Author

hi,

I am using same Qliksense version 3.1SR4 and I got this:

but I don't know the issue with it.

swuehl
MVP
MVP

These variables are most certainly the reason for your different result, since they define a week start and numbering other than ISO.

Have a look at Henric's blog post Peter has linked to in his first answer.