Validation
Validate operation
Quantemplate allows validation rules and actions to be configured via a Validate operation within a pipeline Transform stage. On running the pipeline the results are summarised in a Validation Report.
Validation rules are logical queries configured using Quantemplate’s Equation Editor. This allows flexible queries to be devised, such as checking that the values in a column do not exceed the values in another column, or that the length of a text string is within specified parameters.
If the result of the rule is ‘true’ (e.g. a text string is within a specified length) the validation will pass. If the result is ‘false’ the rule can be set to return a failure or a warning in the validation report.
Adding a Validate operation
To add a Validate operation:
- Open a transform stage and ensure inputs are configured.
- In the operations section click the ‘Add operation’ button.
- Select Validate to add the operation.
- Click on the operation to edit it.
To return to the pipeline view, click the stage name on the top left
Configuring validation rules
To configure a validation rule:
- Click on a row in the validation rules
- Select a column or function (fx) from the suggested list
- Add syntax, values or other columns to the equation
- Add a short text description to the rule, so it’s easy to see what the purpose of the rule is when viewing the Validation Report.
Rules can be duplicated, deleted or re-ordered.
For example an expression ENDOFMONTH('Date of Loss') would be invalid, because it only moves the date.
ENDOFMONTH('Date of Loss')>"20241231" would be valid, because it moves the date then checks that it is after 20241231, so can give a true/false result.
Setting validation actions
If the result of a validation rule is ‘true’ the validation will pass. If the result is ‘false’ the rule can trigger a failure, a warning, or take no action.
Fail validation
Intended for validation results with erroneous values which adversely affect data quality.
Show warning
Intended for validation results which may be cause for concern possibly requiring further investigation.
No action
To disable a validation rule without deleting it, set ‘No action’. This can be useful for incrementally debugging a dataset.
Example
- In the ‘Claim value’ column, values less than 10,000 but greater than 0 will pass validation.
- Values greater than or equal to 10,000 will show a warning.
- Values less than 0 will fail validation.
Reordering validation rules
To reorder validation rules, hover over a drag handle at the right end of the validation rules row. Drag and drop the rule to its new position in the table. The new position will be reflected in the validation report.
Copying validation rules
Validation rules can be copied and pasted all at once to another validation operation. This is useful for duplicating a set of validation rules across multiple pipelines.
To copy rules: open a Validate operation and with no rules selected click ctrl+c (Win) or cmd+c (Mac).
To paste rules: open a Validate operation and click ctrl+v (Win) or cmd+v (Mac). This will add the copied rules below any existing rules.
To duplicate a Validate operation: copy the rules from one operation, create a new Validate operation and paste them in.
Note that the Validate operation will need the same input column names for the rules to work.
Renaming the Validate operation
It is sometimes useful to rename a Validate operation. You may wish to do this to provide a more precise description of the nature of the validations in the operation, or to distinguish between multiple validation operations in a single stage.
To rename the validation operation:
- Enter the Validate operation.
- Click on the ‘Validate’ heading top left.
- Type the new name.
Functions index
The Equation Editor in the Calculate and Validate operations supports a range of Excel-like functions for general purpose data cleansing and set of functions specifically for cleansing dates. To define columns, values and operators in functions, use the syntax described in the Operators and syntax section.
Date functions
General Functions
ABS
Returns the absolute value of a number.
ABS(<column>)
Example
VALUE |
ABS('VALUE') |
|---|---|
1 |
1 |
-1 |
1 |
CONCATENATE
Joins multiple values together to create a single text value.
Note that if named columns are not present, the run will fail. If this is not desired behviour, consider using the Combine Columns operation instead.
CONCATENATE(<column name or value> … )
Example
ID |
CONCATENATE("X", 'ID') |
|---|---|
123 |
X123 |
1234 |
X1234 |
FIND
Finds a text value and returns position of its first character.
FIND(<search within>, <search for>)
Note:
- The first character in the searched text is counted as position 1.
- If no match is found, the value 0 will be returned.
- Searching for a blank value will return 0.
- The match is case-sensitive. To perform a case-insensitive match combine with LOWER, UPPER or PROPER functions:
FIND(UPPER(<search within>), UPPER(<search for>))
Examples
Find the position of the character ‘d’ within the ID column.
ID |
FIND('ID’, “d”) |
|---|---|
abcd |
4 |
defg |
1 |
efgh |
0 |
Extract the first word of a text value, for example extracting a first name from a full name. Note that in this example, if the name does not contain a space, a blank will be returned.
NAME |
LEFT('NAME', FIND('NAME', " ") - 1) |
|---|---|
Ronald Davies |
Ronald |
Jane Alice Smith |
Jane |
F. Scott Fitzgerald |
F. |
Madonna |
Check whether a column contains a given text value, for example check whether a post code contains SE4.
Postcode |
IF(FIND('Postcode', "SE4") > 0, "Yes", "No") |
|---|---|
SE4 5BX |
Yes |
SE13 4WZ |
No |
SE47RS |
Yes |
Remove the first word, for example remove a building number from a street address. This expression looks for the position of the first space and returns everything after that space, returning ‘Unknown’ if no space is found.
Street |
IF(FIND('Street', " ") = 0, "Unknown", MID('Street', FIND('Street', " ") + 1, LENGTH('Street')))
|
|---|---|
23 Acacia Avenue |
Acacia Avenue |
361–364 Park Road |
Park Road |
London |
Unknown |
IF
Checks whether a condition is met and returns one value if true, and another value if false.
IF(<logical query>, <value if true>, <value if false>)
Examples of logical queries:
'Line_of_Business' = "Property"
'Region' = "Americas"
'Claim' > 1000000
IF statement example
If the Line of Business is Property, then multiply premium by 1.2. If it is not Property leave the Premium value unchanged.
IF('Line_of_Business' = "Property", 'Premium' * 1.2, 'Premium')
Using ‘and/or’ in IF statements
The calculation editor supports and/or syntax in IF statements and validations. The words ‘and’ ‘or’ should be entered in lowercase.
‘and’ statement
IF('Column 1' > 'Column 2' and 'Column 3' < 'Column 4',
value_if_true, value_if_false)
‘or’ statement
IF('Column 1' > 'Column 2' or 'Column 3' < 'Column 4',
value_if_true, value_if_false)
Combined ‘and/or’ statement
IF(('Column 1' > 'Column 2' or 'Column 1' < 'Column 5')
and ('Column 3' < 'Column 4'), value_if_true, value_if_false)
Using ‘and/or’ in validations
Validations work like an IF statement, returning a warning or failure if the result is false. Be aware of this when formulating a validation with ‘and/or’ and ‘=/!=’: it may be necessary to invert the ‘and/or’ logic to get the desired result.
‘and/or’ validation examples
Zip must be populated and 5 digits long
ISNUMBER('Zip') and LENGTH('Zip')=5
‘Gross Premium’ must be a negative value when ‘Policy Transaction Type’ = ‘Cancellation’
'Gross Premium'<0 or 'Transaction Type' !=“Cancellation"
If ‘Transaction Type’ = ‘Cancellation’, then ‘Gross Premium’ cannot be greater than sum of ‘Gross Premium’ on all prior transactions
('Compare cancelled GWP against prior periods'>=0) or ('Cancellation flag'!="Cancelled”)
IFERROR
Returns a value if a calculation generates an error.
IFERROR(<calculation>, <value>)
Example
If the calculation ‘claim_amount / claim_count’ generates an error, return the value 0.
IFERROR('claim_amount' / 'claim_count', 0)
ISNUMBER
Returns TRUE if value is a number, and FALSE if not (for use with IF statements).
ISNUMBER(<column>)
Example
value |
IF(ISNUMBER('value'), "Number", "Not a number") |
|---|---|
1 |
Number |
"1" |
Number |
1.2 |
Number |
"" |
Not a number |
"text" |
Not a number |
ISLIKE
Returns TRUE if value matches a regular expression, and FALSE if not (for use with IF statements)
ISLIKE(<column>, "regular expression")
Example
ID |
IF(ISLIKE('ID', "4$"), "Ends with 4", "Doesn't end with 4") |
|---|---|
123 |
Doesn’t end with 4 |
1234 |
Ends with 4 |
LEFT
Returns the first characters from a value, given the number of characters
LEFT(<column>, <no. of characters>)
Example
Address |
LEFT('SIC Code', 4) |
|---|---|
0800 Forestry |
0800 |
2080 Beverages |
2080 |
LENGTH
Returns the length of each column value.
LENGTH(<column>)
Example
ID |
LENGTH('ID') |
|---|---|
123 |
3 |
1234 |
4 |
LOWER
Converts text to lowercase.
LOWER(<column name or text value> … )
MAX
Returns the maximum value across multiple columns or constant values.
Each parameter can be a numeric value or a column name. If the parameter is a column name then the function will get the value in that column. All the values are compared and the largest value is returned.
MAX(<column name or numeric value>, … )
Example
VALUE |
MAX('VALUE',0) |
|---|---|
1 |
1 |
-1 |
0 |
MID
Returns characters from a value, given starting position (where first character is 1) and number of characters.
MID(<column>, <start position>, <no. of characters>)
Example
ID |
MID('ID', 4, 2) |
|---|---|
12345678 |
45 |
abcdefghijkl |
de |
MIN
Returns the minimum value across multiple columns or constant values.
Each parameter can be a numeric value or a column name. If the parameter is a column name then the function will get the value in that column. All the values are compared and the smallest value is returned.
MIN(<column name or numeric value>, … )
Example
VALUE |
MIN('VALUE',0) |
|---|---|
1 |
0 |
-1 |
-1 |
PROPER
Converts the first letter of each word to uppercase and the other letters to lowercase.
PROPER(<column name or text value> … )
Example
VALUE |
PROPER('VALUE') |
|---|---|
SAN FRANCISCO |
San Francisco |
sao paulo |
Sao Paulo |
SAN DIEGO, CA |
San Diego, Ca |
RIGHT
Returns the last characters from a value, given the number of characters
RIGHT(<column>, <no. of characters>)
Example
Address |
RIGHT('Address', 8) |
|---|---|
London, EC1Y 1AA |
EC1Y 1AA |
Penzance, TR19 7AA |
TR19 7AA |
ROUND
Rounds a number to a given number of digits.
ROUND(<column name or numeric value>, <no. of digits>)
Numbers 1–4 are rounded down and 5–9 are rounded up. Numbers are rounded to a specified level of precision. They can be rounded to the right or left of the decimal point.
- If num_digits > 0, number is rounded to the specified number of decimal places to the right of the decimal point.
- If num_digits < 0, number is rounded to the left of the decimal point (i.e. to the nearest 10, 100, 1000, etc.).
- If num_digits = 0, number is rounded to the nearest integer.
Examples
Formula |
Description |
Result |
|---|---|---|
ROUND(3.14, 1) |
Rounds 3.14 to one decimal place |
3.1 |
ROUND(12.34, -1) |
Rounds 12.34 to one decimal place to the left of the decimal point |
10 |
ROUND(876.5, -3) |
Rounds 876.5 to the nearest 1000 |
1000 |
Rounding when the column contains text strings
Trying to round values in columns with mixed text and numbers will result in a ‘NaN’ for the text strings. This can be solved by using IF and ISNUMBER.
Create a column in Calculate called ‘Value’ and enter the following:
IF(ISNUMBER('Value'),ROUND('Value',2),'Value')
SUBSTITUTE
Finds a text value and replaces it with another text value.
SUBSTITUTE(<search within>, <search for>, <replace with>)
Note:
- All instances of the searched for text in the searched within text will be replaced.
- If no searched for text is found, the searched within text is not changed.
- If the searched within text is blank, the result will be blank.
- If the searched for text is blank, the result will be the searched within text, unchanged.
- If the replace with text is blank then the searched for text will be removed.
- The match is case-sensitive.
Example
Remove dashes from an ID value.
ID |
SUBSTITUTE('ID', "-", "") |
|---|---|
QUAN-1234-785 |
QUAN1234785 |
QUAN7436528 |
QUAN7436528 |
SUBSTRING
Returns characters from a value, given starting position (where first character is 0) and number of characters.
SUBSTRING(<column>, <start position>, <no. of characters>)
Example
ID |
SUBSTRING('ID', 4, 2) |
|---|---|
12345678 |
56 |
abcdefghijkl |
ef |
TRIM
Removes extra spaces from text: leading and trailing whitespace and repeated spaces between words.
TRIM(<column name or text value> … )
UPPER
Converts text to uppercase.
UPPER(<column name or text value> … )
Date Functions
Date functions operate on cleansed date values which are in Basic ISO format
- Blank date values are left blank
- Date values that are not in Basic ISO format will cause the pipeline run to fail.
See Working with dates to learn more about how Quantemplate processes dates.
DATECALC
Returns a new basic-ISO formatted date by adding or removing a term (constant value or column reference) from a basic-ISO date.
DATECALC(<iso date>, <term (numeric value)>, <unit>)
- The term is rounded to the lowest whole number (negative values are rounded up towards zero).
- Adding or subtracting by month/year to a day that is invalid (e.g. to 31st April) will truncate to the last valid day of that month
- <unit> is one of "d"/"day"/"days"; "m"/"month"/"months"; or "y"/"year"/"years"
Example
Premium |
DATECALC('Premium', -1, "year") |
DATECALC('Premium', 6, "months") |
|---|---|---|
20120629 |
20110629 |
20121229 |
20200229 |
20190228 |
20200829 |
"" |
"" |
"" |
2012-06-29 |
(pipeline error) |
(pipeline error) |
DURATION
Returns the number of whole elapsed units between two basic-ISO dates.
DURATION(<start>, <end>, <unit>)
- The result is rounded to the lowest whole number (negative values are rounded up towards zero).
- If the end is before the start, a negative number will be returned.
- <unit> is one of "d"/"day"/"days"; "m"/"month"/"months"; or "y"/"year"/"years"
Example
Start |
End |
DURATION('Start', 'End', "days") |
|---|---|---|
20120629 |
20120630 |
1 |
20120630 |
20120629 |
-1 |
"" |
"" |
"" |
2012-06-29 |
2012-06-30 |
(pipeline error) |
ENDOFQUARTER
Moves a date to the last day in a quarter.
ENDOFQUARTER(<iso date>)
ENDOFMONTH
Moves a date to the last day in a month.
ENDOFMONTH(<iso date>)
ENDOFYEAR
Moves a date to the last day in a year.
ENDOFYEAR(<iso date>)
STARTOFQUARTER
Moves a date to the first day in a quarter.
STARTOFQUARTER(<iso date>)
STARTOFMONTH
Moves a date to the first day in a month.
STARTOFMONTH(<iso date>)
STARTOFYEAR
Moves a date to the first day in a year.
STARTOFYEAR(<iso date>)
Operators and syntax
+
-
/
*
^
=
!=
>
<
>=
<=
“ ”
IF(...)
,
and lozenged if validated.
Double quotes for categorical values in your data, eg ‘Region’=“America”
Brackets must follow a function.
Comma must follow a field or value in the function.
Notation
Certain combinations of letters and numbers will be interpreted as numbers in arithmetic operations.
The most useful of these is the exponent indicator ‘e’, so a string ‘5e5’ would be interpreted as the number ‘500,000’ when used in an arithmetic expression.
Characters f, F, d and D indicate the type of floating-point number. F or f indicates the number is a float; otherwise its type is double and it can optionally be suffixed with a letter D or d.