Value in range date percent
Description
The valuein_range_date_percent
calculates the percentage of records that are within a certain date range.
Date range is configurable by the user by defining min_value
and max_value
check parameters. It is also possible to
decide whether to include upper and lower bounds of the range, they are included by default.
Warning
There are four acceptable data types: DATE
, DATETIME
, TIMESTAMP
, STRING
. This check is set to validate
date
values, so in the other three cases CAST()
is performed, so keep in mind that casting is not always
possible. The safest option is to provide the data in ISO 8601
format, in other cases formatting might be
necessary.
When to use
This sensor is used when you need to confirm that the event took place in a certain time period.
Used sensor
Accepted rules
Parameters
min_value
: str
minimal value range variable, should be provided inISO 8601
formatmax_value
: str
maximal value range variable, should be provided inISO 8601
formatinclude_min_value
: bool (Optional)
a variable deciding whether to include the lower limit of the range (default:true
)include_min_value
: bool (Optional)
a variable deciding whether to include the upper limit of the range (default:true
)
Warning
The default date format is ISO 8601
, if your data set contains date values it should be formatted correctly,
otherwise you might not get the results.
How to use
Default configuration
Table configuration in YAML file for column check value_in_range_date_percent
on a column real_datetime
in
string_dates
table in test_data
dataset in dqo-ai project on BigQuery, min_count rule and passed parameters min_value = "2022-04-01"
, max_value
= "2022-04-10"
SELECT
100.0 * SUM(
CASE
WHEN SAFE_CAST(analyzed_table.`reference_datetime` AS DATE) >= '2022-04-01' AND SAFE_CAST(analyzed_table.`reference_datetime` AS DATE) <= '2022-04-10' THEN 1
ELSE 0
END
) / COUNT(*) AS actual_value
FROM `dqo-ai-testing`.`dqo_ai_test_data`.`test_data_timeliness_sensors_1287831065858823464` AS analyzed_table