This function determines if timestamp lies inside the
lunar week
containing base_date. Lunar weeks in Qlik Sense are defined by counting January 1 as the first day of the week., Apart from the final week of the year, each week will contain exactly seven days.
In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.
The inlunarweek() function determines which lunar week the base_date falls into. It then returns a Boolean result once it has determined whether each timestamp value occurs during the same lunar week as the base_date.
When to use it
The inlunarweek() function returns a Boolean result. Typically, this type of function will be used as a condition in an IF expression. This would return an aggregation or calculation dependent on whether the date evaluated occurred during the lunar week in question.
For example, the inlunarweek() function can be used to identify all equipment manufactured in a particular lunar week.
Arguments
Argument
Description
timestamp
The date that you want to compare with base_date.
base_date
Date that is used to evaluate the lunar week.
period_no
The lunar
week can be offset by period_no.
period_no is an integer, where the
value 0 indicates the lunar week which contains base_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.
Function examples
Example
Result
inlunarweek('01/12/2013', '01/14/2013',
0)
Returns TRUE, since the value of timestamp, 01/12/2013, falls in the week 01/08/2013 to 01/14/2013.
inlunarweek('01/12/2013', '01/07/2013',
0)
Returns FALSE, since the base_date01/07/2013 is in the lunar week defined as 01/01/2013 to 01/07/2013.
inlunarweek('01/12/2013', '01/14/2013',
-1)
Returns FALSE. Specifying a value of period_no as -1 shifts the week to the previous week, 01/01/2013 to 01/07/2013.
inlunarweek('01/07/2013', 01/14/2013',
-1)
Returns TRUE. In comparison with the previous example, the timestamp is in the following week, after into account the shift backwards.
inlunarweek('01/11/2006', '01/08/2006',
0, 3)
Returns FALSE. Specifying a value of 3 for first_week_day means that the start of the year is calculated from 01/04/2013. Therefore, the value of base_date falls in the first week, and the value of timestamp falls in the week 01/11/2013 to 01/17/2013.
The inlunarweek() function is often used in combination with the following functions:
This function is used to determine the lunar week number of the year in which an input date occurs.
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.
Default regional settings in apps are based on the regional system settings of the computer or server where Qlik Sense is installed. If the Qlik Sense server you are accessing is set to Sweden, the Data load editor will use Swedish regional settings for dates, time, and currency. These regional format settings are not related to the language displayed in the Qlik Sense user interface. Qlik Sense will be displayed in the same language as the browser you are using.
Example 1 - No additional arguments
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset of transactions for the month of January, which is loaded into a table called Transactions.
The date field has been provided in the DateFormat system variable (MM/DD/YYYY) format.
Create a field, in_lunar_week, that determines whether the transactions took place in the same lunar week as January 10.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_lunar_week
Results table
date
in_lunar_week
1/5/2022
0
1/6/2022
0
1/7/2022
0
1/8/2022
-1
1/9/2022
-1
1/10/2022
-1
1/11/2022
-1
1/12/2022
-1
1/13/2022
-1
1/14/2022
-1
1/15/2022
0
1/16/2022
0
1/17/2022
0
1/18/2022
0
1/19/2022
0
1/20/2022
0
1/21/2022
0
1/22/2022
0
1/23/2022
0
The in_lunar_week field is created in the preceding load statement by using the inlunarweek() function, then passing the following as the function's arguments:
The date field
A hard-coded date for January 10 as the base_date
Aperiod_no of 0
Because lunar weeks begin on January 1, January 10 would fall in the lunar week that begins on January 8 and ends on January 14. Therefore, any transactions that occur between those two dates in January would return a Boolean value of TRUE. This is validated in the results table.
Example 2 - period_no
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset and scenario as the first example.
The date field has been provided in the DateFormat system variable (MM/DD/YYYY) format.
However, in this example, the task is to create a field, 2_lunar_weeks_later, that determines whether or not the transactions took place two lunar weeks after January 10.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
2_lunar_weeks_later
Results table
date
2_lunar_weeks_later
1/5/2022
0
1/6/2022
0
1/7/2022
0
1/8/2022
0
1/9/2022
0
1/10/2022
0
1/11/2022
0
1/12/2022
0
1/13/2022
0
1/14/2022
0
1/15/2022
0
1/16/2022
0
1/17/2022
0
1/18/2022
0
1/19/2022
0
1/20/2022
0
1/21/2022
0
1/22/2022
-1
1/23/2022
-1
In this instance, because a period_no of 2 was used as the offset argument in the inlunarweek() function, the function defines the week beginning on January 22 as the lunar week to validate transactions against. Therefore, any transaction that takes place between the January 22 and January 28 will return a Boolean result of TRUE.
Example 3 - first_week_day
Overview
Open the Data load editor and add the load script below to a new tab.
The load script uses the same dataset and scenario as the first example. However, in the example, we set lunar weeks to begin on January 6.
The same dataset and scenario as the first example.
The default DateFormat system variable MM/DD/YYYY is used.
A first_week_day argument of 5. This sets lunar weeks to begin on January 5.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_lunar_week
Results table
date
in_lunar_week
1/5/2022
0
1/6/2022
-1
1/7/2022
-1
1/8/2022
-1
1/9/2022
-1
1/10/2022
-1
1/11/2022
-1
1/12/2022
-1
1/13/2022
0
1/14/2022
0
1/15/2022
0
1/16/2022
0
1/17/2022
0
1/18/2022
0
1/19/2022
0
1/20/2022
0
1/21/2022
0
1/22/2022
0
1/23/2022
0
In this instance, because the first_week_date argument of 5 is used in the inlunarweek() function, it offsets the start of the lunar week calendar to January 6. Therefore, January 10 falls in the lunar week beginning on January 6 and ending on January 12. Any transaction that falls between these two dates will return a Boolean value of TRUE.
Example 4 - Chart object
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset and scenario as the first example.
The date field has been provided in the DateFormat system variable (MM/DD/YYYY) format.
However, in this example, the unchanged dataset is loaded into the application. The calculation that determines whether the transactions took place in the same lunar week as January 10 is created as a measure in a chart object of the application.
Load the data and open a sheet. Create a new table and add this field as a dimension: date.
To calculate whether a transaction takes place in the lunar week that contains January 10, create the following measure:
= inlunarweek(date,'01/10/2022', 0)
Results table
date
=inlunarweek(date,'01/10/2022', 0)
1/5/2022
0
1/6/2022
0
1/7/2022
0
1/8/2022
-1
1/9/2022
-1
1/10/2022
-1
1/11/2022
-1
1/12/2022
-1
1/13/2022
-1
1/14/2022
-1
1/15/2022
0
1/16/2022
0
1/17/2022
0
1/18/2022
0
1/19/2022
0
1/20/2022
0
1/21/2022
0
1/22/2022
0
1/23/2022
0
Example 5 - Scenario
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset which is loaded into a table called Products.
Information consisting of product ID, manufacture date, and cost price.
It has been identified that due to equipment error, products that were manufactured in the lunar week that included January 12 were defective. The end user would like a chart object that displays, by lunar week name, the status of whether the products manufactured were ‘defective’ or ‘faultless’ and the cost of the products manufactured in that month.
The inlunarweek() function returns a Boolean value when evaluating the manufacturing dates of each of the products. For any product manufactured in the lunar week that contains January 10, the inlunarweek() function returns a Boolean value of TRUE and marks the products as ‘Defective’. For any product returning a value of FALSE, and therefore not manufactured in that week, it marks the products as ‘Faultless’.
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!