The inday() function uses the base_timestamp argument to identify which day the timestamp falls into. The start time of the day is, by default, midnight; but you can change the start time of the day by using the day_start argument of the inday() function. Once this day is defined, the function will return Boolean results when comparing the prescribed timestamp values to that day.
When to use it
The inday() function returns a Boolean result. Typically, this type of function will be used as a condition in an if expression. This returns an aggregation or calculation dependent on whether a date evaluated occurred in the day of the timestamp in question.
For example, the inday() function can be used to identify all equipment manufactured in a given day.
Return data type: Boolean
In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.
Arguments
Argument
Description
timestamp
The date and time that you want to compare with base_timestamp.
base_timestamp
Date and time that is used to evaluate the timestamp.
period_no
The day can be offset by period_no.
period_no is an integer, where the
value 0 indicates the day which contains base_timestamp.
Negative values in period_no indicate
preceding days and positive values indicate succeeding days.
day_start
If you want
to work with days not starting midnight, indicate an offset as a
fraction of a day in day_start,
For example, 0.125 to denote 3 AM.
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.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_day
Results table
date
in_day
01/01/2022 7:34:46 PM
0
01/01/2022 10:10:22 PM
0
01/02/2022 8:35:54 AM
0
01/03/2022 2:21:53 PM
0
01/04/2022 6:49:38 PM
0
01/04/2022 10:58:34 PM
0
01/05/2022 5:40:49 AM
-1
01/05/2022 11:29:38 AM
-1
01/05/2022 7:04:57 PM
-1
01/06/2022 8:49:09 AM
0
The in_day field is created in the preceding load statement by using the inday() function and passing the date field, a hard-coded timestamp for January 5 and a period_no of 0 as the function’s arguments.
Example 2 – period_no
Overview
The load script uses the same dataset and scenario that were used in the first example.
However, in this example, the task is to calculate whether the transaction date occurred two days before January 5.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_day
Results table
date
in_day
01/01/2022 7:34:46 PM
0
01/01/2022 10:10:22 PM
0
01/02/2022 8:35:54 AM
0
01/03/2022 2:21:53 PM
-1
01/04/2022 6:49:38 PM
0
01/04/2022 10:58:34 PM
0
01/05/2022 5:40:49 AM
0
01/05/2022 11:29:38 AM
0
01/05/2022 7:04:57 PM
0
01/06/2022 8:49:09 AM
0
In this instance, because a period_no of -2 is used as the offset argument in the inday() function, the function determines whether each transaction date took place on January 3. This can be verified in the output table where one transaction returns a Boolean result of TRUE.
Example 3 – day_start
Overview
The load script uses the same dataset and scenario that were used in the previous examples.
However, in this example, the company policy is that the workday begins and ends at 7 AM.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_day
Results table
date
in_day
01/01/2022 7:34:46 PM
0
01/01/2022 10:10:22 PM
0
01/02/2022 8:35:54 AM
0
01/03/2022 2:21:53 PM
0
01/04/2022 6:49:38 PM
-1
01/04/2022 10:58:34 PM
-1
01/05/2022 5:40:49 AM
-1
01/05/2022 11:29:38 AM
0
01/05/2022 7:04:57 PM
0
01/06/2022 8:49:09 AM
0
Because the start_day argument of 7/24, which is 7 AM, is used in the inday() function, the function determines whether each transaction date took place on January 4 from 7 AM and January 5 before 7 AM.
This can be verified in the output table where transactions that take place after 7 AM on January 4 return a Boolean result of TRUE whilst transactions that take place after 7 AM on January 5 return a Boolean result of FALSE.
Example 4 – Chart object
Overview
The load script uses the same dataset and scenario that were used in the previous examples.
However, in this example, the dataset is unchanged and loaded into the application. You will calculate to determine if a transaction takes place on January 5 by creating a measure in a chart object.
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 on January 5, create the following measure:
=inday(date,'01/05/2022 12:00:00 AM',0)
Results table
date
inday(date,'01/05/2022 12:00:00 AM',0)
01/01/2022 7:34:46 PM
0
01/01/2022 10:10:22 PM
0
01/02/2022 8:35:54 AM
0
01/03/2022 2:21:53 PM
0
01/04/2022 6:49:38 PM
0
01/04/2022 10:58:34 PM
0
01/05/2022 5:40:49 AM
-1
01/05/2022 11:29:38 AM
-1
01/05/2022 7:04:57 PM
-1
01/06/2022 8:49:09 AM
0
Example 5 – Scenario
Overview
In this example, it has been identified that due to equipment error, products that were manufactured on January 5 were defective. The end user would like a chart object that displays, by date, the status of which products that were manufactured were ‘defective’ or ‘faultless’ and the cost of the products manufactured on January 5.
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’.
The inday() function returns a Boolean value when evaluating the manufacturing dates of each of the products. For any product manufactured on January 5, the inday() 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 on that day, it marks the products as ‘Faultless’.
Aggregation
An aggregation is a calculation using multiple records in the source tables. Often it is a single field aggregated with a function such as sum, count, min, max, or average. For example, the sum of sales.
The term dataset is sometimes synonymous with table. It can refer to the original source table, the table after undergoing transformations, or the fact and dimension tables in a data mart.
It can also refer to a logical table, where there are several instance tables and views:
Current data
History, which holds previous versions of the table
A field contains values, loaded from a data source. At a basic level, a field corresponds to a column in a table. Fields are used to create dimensions and measures in visualizations.
A preceding load is a script construct that allows you to load from the following LOAD or SELECT statement without specifying that source. Preceding loads are often faster than resident loads.
The load script is a sequence of statements that defines what data to load and how to link the different loaded tables. It can be generated with the Data manager, or with the Data load editor, where it also can be viewed and edited.
A measure is a calculation base on one ore more aggregations. For example, the sum of sales is a single aggregation, while the sum of sales divided by the count of customers is a measure based on two aggregations.