# qlik sense How-to-group-numbers-in-range by IntervalMatch function

## Background

Sometimes we need to use qlik to group the data in range, for example, matching 60 points to 80 points as good, 80 points to 100 points as excellent

## Sulution

Score:
Score, Name
77, Apple
4, Orange
99, Banana
100, GOD
];

ScoreRange:
Start, End, Evaluation
0, 60, COOL
61, 80, GOOD
81, 100, EXCELLENT
];

Inner Join IntervalMatch ( Score)
Resident ScoreRange;


result:

by zhengkai.blog.csdn.net

Score, Name,Evaluation
77, Apple , GOOD
4, Orange , COOL
99, Banana, EXCELLENT
100, GOD, EXCELLENT


## Knowledge

The IntervalMatch prefix is used to create a table matching discrete numeric values to one or more numeric intervals, and optionally matching the values of one or several additional keys.

IntervalMatch 前缀用于创建表格以便将离散数值与一个或多个数值间隔进行匹配，并且任选匹配一个或多个额外关键值。

Syntax:

• IntervalMatch (matchfield)(loadstatement | selectstatement )
• IntervalMatch (matchfield,keyfield1 [ , keyfield2, … keyfield5 ] ) (loadstatement | selectstatement )

The IntervalMatch prefix must be placed before a LOAD or a SELECT statement that loads the intervals. The field containing the discrete data points (Time in the example below) and additional keys must already have been loaded into QlikView before the statement with the IntervalMatch prefix. The prefix does not by itself read this field from the database table. The prefix transforms the loaded table of intervals and keys to a table that contains an additional column: the discrete numeric data points. It also expands the number of records so that the new table has one record per possible combination of discrete data point, interval and value of the key field(s).

IntervalMatch 前缀必须置于加载时间间隔的 LOAD 或 SELECT 语句之前。在使用此语句和 IntervalMatch 前缀之前，包含离散数据点的字段（以下所示的 Time）必须已经加载到 Qlik Sense。此前缀不会从数据库表格中读取此字段。此前缀将加载的时间间隔表格转换为包含其他列（离散数值数据点）的表格。另外其扩展了记录数，以使新表格对离散数据点、时间间隔和关键字段值的每个可能组合都有一条记录。

The intervals may be overlapping and the discrete values will be linked to all matching intervals.

The extended IntervalMatch prefix is used to create a table matching discrete numeric values to one or more numeric intervals, while at the same time matching the values of one or several additional keys. This is a very powerful and flexible feature that can be used for linking transactions with dimensions that are changing over time: Slowly changing dimensions.

In order to avoid undefined interval limits being disregarded, it may be necessary to allow NULL values to map to other fields that constitute the lower or upper limits to the interval. This can be handled by the NullAsValue statement or by an explicit test that replaces NULL values with a numeric value well before or after any of the discrete numeric data points.

Arguments:

ArgumentDescription描述
matchfieldThe field containing the discrete numeric values to be linked to intervals.一个字段，包含链接至时间间隔的离散数值。
keyfieldFields that contain the additional attributes that are to be matched in the transformation.一个字段，包含转换中匹配的额外属性。
loadstatement or selectstatementMust result in a table, where the first field contains the lower limit of each interval, the second field contains the upper limit of each interval, and in the case of using key matching, the third and any subsequent fields contain the keyfield(s) present in the IntervalMatch statement. The intervals are always closed, i.e. the end points are included in the interval. Non-numeric limits render the interval to be disregarded (undefined).必会生成一个表格，其中第一个字段包含每个时间间隔的下半部限制，第二个字段包含每个时间间隔的上半部限制，如果使用关键字匹配，则第三个及此后的任何字段包含显示于 IntervalMatch 语句中的关键字段值。时间间隔总是封闭区间，即间隔的端点包括在时间间隔之中。非数值限值会导致时间间隔遭到忽略（未定义）。
EventLog:
Time, Event, Comment
00:00, 0, Start of shift 1
01:18, 1, Line stop
02:23, 2, Line restart 50%
04:15, 3, Line speed 100%
08:00, 4, Start of shift 2
11:43, 5, End of production
];

OrderLog:
Start, End, Order
01:00, 03:35, A
02:30, 07:58, B
03:04, 10:27, C
07:23, 11:43, D
];

//Link the field Time to the time intervals defined by the fields Start and End.
Inner Join IntervalMatch ( Time )
Resident OrderLog;


Time Start End Order

00:00

- - -
01:18 01:00 03:35 A
02:23 01:00 03:35 A
04:15 02:30 07:58 B
04:15 03:04 10:27 C
08:00 03:04 10:27 C
08:00 07:23 11:43 D
11:43 07:23

11:43

D

12-20
10-24
06-07
09-20 1414
08-21
07-19
01-18 2410