Skip to main content Skip to complementary content

lunarweekstart - script and chart function

This function returns a value corresponding to a timestamp of the first millisecond of the first day of the lunar week containing date. Lunar weeks in Qlik Sense are defined by counting January 1 as the first day of the week and, apart from the final week of the year, will contain exactly seven days.

Syntax:  

LunarweekStart(date[, period_no[, first_week_day]])

Return data type: dual

The lunarweekstart() function determines which lunar week the date falls into. It then returns a timestamp, in date format, for the first millisecond of that week.

Example diagram of lunarweekstart() function

Example diagram showing how the lunarweekstart function converts an input date into a timestamp for the first millisecond of the lunar week in which the input date occurs.
Arguments
Argument Description
date The date or timestamp to evaluate.
period_no period_no is an integer or expression resolving to an integer, where the value 0 indicates the lunar week which contains date. Negative values in period_no indicate preceding lunar weeks and positive values indicate succeeding lunar weeks.
first_week_day An offset that may be greater than or less than zero. This changes the beginning of the year by the specified number of days and/or fractions of a day.

When to use it

The lunarweekstart() function is commonly used as part of an expression when the user would like the calculation to use the fraction of the week that has elapsed thus far. Unlike the weekstart() function, at the start of each new calendar year, week’s begin on January 1 and each subsequent week begins seven days later. The lunarweekstart() function is not affected by the FirstWeekDay system variable.

For example, the lunarweekstart() can be used to calculate the interest that has been accumulated in a week to date.

Function examples
Example Result
lunarweekstart('01/12/2013') Returns 01/08/2013.
lunarweekstart('01/12/2013', -1) Returns 01/01/2013.
lunarweekstart('01/12/2013', 0, 1 ) Returns 01/09/2013, because setting first_week_day to 1 means the beginning of the year is changed to 01/02/2013.

Regional settings

Unless otherwise specified, the examples in this topic use the following date format: MM/DD/YYYY. The date format is specified in the SET DateFormat statement in your data load script. The default date formatting may be different in your system, due to your regional settings and other factors. You can change the formats in the examples below to suit your requirements. Or you can change the formats in your load script to match these examples. For more information, see Modifying regional settings for apps and scripts.

Default regional settings in apps are based on the user profile. These regional format settings are not related to the language displayed in the Qlik Cloud user interface. Qlik Cloud will be displayed in the same language as the browser you are using.

If you are an app creator, you can set the default region for apps you create. For more information, see Setting your preferred regional settings for creating apps and scripts in Qlik Cloud Analytics.

Example 1 – No additional arguments

Example 2 – period_no

Example 3 – first_week_day

Example 4 – Chart object example

Example 5 – Scenario

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!