Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
hic
Former Employee
Former Employee

Six days thou shalt work, but on the seventh day thou shalt rest.

                                                                             [Exodus 34:21]

The idea that you should rest on the seventh day is a central concept in both Christianity and Judaism. But which weekday is the seventh day of the week? And which day is the first?

The old texts of the Abrahamic religions clearly consider the Sabbath – Saturday – as the seventh day of the week. This day is also still today the resting day for Jews around the world. The same texts also describe how Adam was created on the sixth day, which is one of the reasons why Friday is the day of congregation and prayers for Muslims.

Hence, these two religions agree on the numbering of week days: Friday is the sixth day of the week and Saturday is the seventh.

However, in the rest of the world, the situation is more confusing: Although Sunday is observed as resting day in most countries, there is a disagreement on whether Sunday is the first or the seventh day of the week. In North America, Sunday is the first day of the week, but in many European countries it is the last day of the week. According to the International Organization for Standardization (ISO 8601), the week starts on a Monday, and Sunday is thus the seventh and last day of the week.

How weekdays are ordered makes a difference in all Business Intelligence applications, most notably in how list boxes and charts are sorted. Note the order of the week days in the list boxes below. In the left one, Sunday is on top of the list and in the right one it is Monday.

List box Sunday.png     List box Monday.png

This difference can also be seen in calendar displays, used in many types of software and on many sites in the web. Again, note the order of the week days.

SMTWTFS.png     MTWTFSS.png

QlikView uses ISO 8601 to define the week days and the week start. WeekDay() returns the name of the week day (as defined in the variable DayNames) and a number from 0 to 6;  Monday being day number 0. WeekStart() returns the date of the Monday immediately before the date supplied as parameter.

If you want redefine this, e.g. if you want QlikView to show Sunday as the first day of the week – here’s how you do it:

Start by creating a variable that defines the beginning of the week:

     Set vCal_FD = 6; // First Day of the week (0=Mon, 1=Tue, ... , 6=Sun)

The WeekStart() function has an offset parameter, and if you use your variable here, you can redefine how the function works and get the week start on the correct day:

     WeekStart( Date, 0, $(vCal_FD) ) as WeekStart

The WeekDay() function, however, cannot take any offset parameter, so you need to define the week day using the Dual() function:

     Dual( WeekDay( Date ), Mod( WeekDay( Date - $(vCal_FD) ), 7 ) +1 ) as WeekDay

Using these two expressions in your Master Calendar instead of the standard function calls, you can redefine the week start to any of the week days.

HIC

Further reading related to this topic:

Ancient Gods and Modern Days

Redefining the Week Numbers

Redefining the Week Start in Qlik Sense

26 Comments
hic
Former Employee
Former Employee

Take a look at the scripts found on Calendars. In them, there is a parameter where you can define which day to use as the first day of the week.

HIC

0 Likes
1,969 Views
vamshi87
Contributor II
Contributor II

Hi Henric,

Has something changed in QlikView 12 to consider the system settings? The reason I am asking is tmy initial default script got generated as below:

SET FirstWeekDay= 6;

I had to manually change this to SET FirstWeekDay =0 to make Monday the First Day of Week.

0 Likes
1,969 Views
hic
Former Employee
Former Employee

This variable is new for QlikView 12. It didn't exist in QlikView 11.

When you create a new document, QlikView will fetch this information from the system settings of your computer. So, if you have Sunday as first day of week there, you will get it in your QlikView document too.

HIC

0 Likes
1,969 Views
vamshi87
Contributor II
Contributor II

Thanks Henric!

0 Likes
1,969 Views
Or
MVP
MVP

Hey Henric,

I also noticed this change, but it doesn't seem to work as expected, at least - not with WeekName().

SET FirstWeekDay=6;

SET BrokenWeeks=1;

SET ReferenceDay=4;

No matter what I set the ReferenceDay and BrokenWeeks to, weeks are numbered in the same manner - Week 2017/52 contains December 31st through January 6th. Obviously this is 'incorrect' - if the reference day is 4, it is my understanding that the week containing January 4th should always be week 1.

Near as I can tell, both BrokenWeeks and ReferenceDay don't actually do anything - I set them to 0 and no change, I set ReferenceDay to 11 and no change in week numbering. So - FirstWeekDay does seem to work correctly (the week is starting on a Sunday), but it throws off the week numbering if used.

0 Likes
1,916 Views
hic
Former Employee
Former Employee

Thanks for letting me know. It sounds like it doesn't do what it is supposed to. I'll take a look at it.  /HIC

0 Likes
1,916 Views