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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anil_Babu_Samineni

Redefining the Week Numbers

Hello,

Why my week is not working Properly, Up to Year end should show week 52/53 and then should be start the week from 1 Again.

Redefining the Week Numbers

Can you please help me.

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
1 Solution

Accepted Solutions
Anil_Babu_Samineni
Author

Rudolf, I got it. Thanks for your Help

I's working with this code

Let vCal_FD = 0; // First Day of the week {0=Mon, 1=Tue, ... , 6=Sun}

Let vCal_BW = 0; // Broken Weeks allowed {0=No, 1=Yes}

Let vCal_RD = 1; // Reference day = This day in Jan defines week one {1..7}

Load

  *,

  if(TempDate < WeekRefDate and WeekNumber=0 and year(TempDate)<WeekYear,53,WeekNumber+1) as Actual_WeekNumber;

Load *,

          Div( TempDate - WeekStart( WeekYearRefDate, 1, $(vCal_FD) ) + 7, 7 ) as WeekNumber,

          Year( WeekYearRefDate ) as WeekYear;

Load *,

          Date( YearStart( If( $(vCal_BW), TempDate, WeekRefDate )) + $(vCal_RD) - 1) as WeekYearRefDate ;

Load *,

          Date( WeekStart( TempDate , 1, $(vCal_FD) ) - $(vCal_RD) ) as WeekRefDate ;

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

View solution in original post

17 Replies
Anonymous
Not applicable

there is a definition which week have to be week 1 (see Wikipedia).

so it may be that some of the Dates of end of december are already in week 1

sometimes the first Dates of a year can be week 52/53!

if you Need a different calendar you may e.g. create virtual week 53v if your business requries it

Anil_Babu_Samineni
Author

Rudolf, Thanks for your Suggestion. Did you get a chance to look to see that URL?

Please find my image, In that how HIC is calculating for Broken Weeks Possible?

Table 6x4.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
Anonymous
Not applicable

I donot understand? what is HIC?

If you want a calendar like "broken weeks possible" you Need to create your own mastercalendar with a column week and create your own week

e.g. if (week(yourdate)=1 AND month(yourdate='dec'), 53, week(yourdate)) as weekbroken

my customer expects exactly this behaviour and I realized it this way with virtual weeks (some years have real week 53, so no virtual week needed)

Anil_Babu_Samineni
Author

HIC Means --

Henric Cronström

Which i share the Link, He only created that..

Can you please help on my Calendar

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
Anonymous
Not applicable

add to to your mastercalendar (my enhancement):

  if (Week(yourdate)=1 AND DAY(yourdate)> 20, // test for week 1 in december
53,   // force virtual week 53

  week(yourdate) as week

all other fields (month, year, day) can remain in your ,mastercalender

only week Need to be adjusted

Anil_Babu_Samineni
Author

See this, My master calendar looks like this

MasterCalendar:

LOAD TempDate AS "MainDate",

week(TempDate) AS Week,

year(TempDate) AS Year,

Day(TempDate) AS Day,

month(TempDate) AS Month,

weekday(TempDate) AS WeekDay,

RESIDENT TempCalendar;

drop table TempCalendar;


Please tell me where i need to Add that?

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
Anonymous
Not applicable

try this code:

MasterCalendar:

LOAD TempDate AS "MainDate",

  if (Week(TempDate)=1 AND month(TempDate)='Dec', //  test for week 1 in december
53,   // force virtual week 53

  week(TempDate) as Week

year(TempDate) AS Year,

Day(TempDate) AS Day,

month(TempDate) AS Month,

weekday(TempDate) AS WeekDay,

RESIDENT TempCalendar;

drop table TempCalendar;

Anil_Babu_Samineni
Author

If i use that if (Week(TempDate)=1 AND month(TempDate)='Dec' -- How to Close If {Bracket} here. Getting error

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
Anonymous
Not applicable

could not test Expression, but ending bracket was missing before as

MasterCalendar:

LOAD TempDate AS "MainDate",

  if (Week(TempDate)=1 AND month(TempDate)='Dec', //  test for week 1 in december
53,   // force virtual week 53

  week(TempDate)) as Week

year(TempDate) AS Year,

Day(TempDate) AS Day,

month(TempDate) AS Month,

weekday(TempDate) AS WeekDay,

RESIDENT TempCalendar;

drop table TempCalendar;