Ryan H
09/30/2025, 5:23 PMkapa.ai
09/30/2025, 5:23 PMkapa.ai
09/30/2025, 5:23 PMdatetime_now_utc_as_string macro. This will affect the detected_at and generated_at fields for all dbt artifacts uploaded by Elementary, allowing you to simulate test runs as if they occurred at a specific date and time. [See more details here](https://github.com/elementary-data/dbt-data-reliability/blob/master/macros/edr/system/system_utils/times.sql#L9). 2. Edit the detected_at field in test results: If you only care about the test results, you can directly edit the detected_at field in the test result dictionary. [Reference to the relevant macro](https://github.com/elementary-data/dbt-data-reliability/blob/master/macros/edr/materializations/test/test.sql#L206). These approaches let you "fake" the test execution date without repopulating your tables. This is useful for demos or for testing how your anomaly tests behave for historical dates. [Source: Slack discussion on setting a fake time for tests](https://slack.com/archives/C02CTC89LAX/p1694607646684209). Let me know if you need guidance on how to implement these overrides!Ryan H
09/30/2025, 6:12 PM{% macro datetime_now_utc_as_string() %}
--{% do return(modules.datetime.datetime.utcnow().strftime(elementary.get_time_format())) %}
'2025-08-01 12:00:00'
{% endmacro %}
And it still runs the test for the most recent datakapa.ai
09/30/2025, 6:12 PMkapa.ai
09/30/2025, 6:13 PMdatetime_now_utc_as_string macro as you did will change the value of detected_at and generated_at in the test results, but it does not affect which data Elementary selects for anomaly detection. The data that is tested is determined by the values in your data's timestamp column and the configuration of days_back, time_bucket, and related parameters. Elementary uses the timestamp_column in your data and slices it according to the time_bucket and days_back settings. The macro you overrode only changes the timestamp recorded for when the test was run, not the data that is selected for testing. This is confirmed in the knowledge sources, where users have tried similar approaches and found that the test still runs on the most recent data, not on historical data as intended. The only way to change which data is tested is to adjust your data or the test configuration, not the macro for the current time [[Slack discussion: setting a fake time for tests](https://slack.com/archives/C02CTC89LAX/p1694607646684209)]. If you want to test anomaly detection for a specific historical date without repopulating your tables, there is no documented way in the knowledge sources to force Elementary to "pretend" it is running in the past for the purpose of data selection. The macro override only affects the metadata, not the data window being analyzed. If you need to test for a specific date, you would need to either: - Adjust your data so that the most recent data matches the date you want to test, or - Change your test configuration (e.g., where_expression, days_back, time_bucket) to focus on the desired date range. I'm sorry, but the knowledge sources do not contain a method to run Elementary anomaly tests for a given date without repopulating your tables or changing your test configuration.Ryan H
09/30/2025, 7:24 PMkapa.ai
09/30/2025, 7:24 PMkapa.ai
09/30/2025, 7:24 PMwhere_expression to limit the data seen by your Elementary anomaly test, the effective training set size can decrease if your filter excludes rows that would otherwise be part of the training period. This is expected behavior, as the training set is built from the filtered data. To ensure you still get the desired amount of training data, you should increase your training_period (or days_back) so that, after filtering, you have enough data points to meet your min_training_set_size. For example, if your filter only includes 1 out of every 7 days, you may need to set your training_period to a much larger window to accumulate enough training data. Elementary will automatically extend the training period to ensure full time buckets and, if you use seasonality, to ensure enough data points for each seasonal group (e.g., enough Mondays, Tuesdays, etc.) [[training_period documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/training-period)]. However, if your filter is very restrictive, you may need to manually set a larger training_period or days_back to compensate for the reduced data volume. There is no built-in way to "force" a minimum number of training data points after filtering, other than by expanding the period from which data is drawn. So, the best practice is to adjust your training_period or days_back accordingly when using a restrictive where_expression [[training_period documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/training-period)]. If you need to guarantee a specific number of training data points, you will need to experiment with your filter and period settings to ensure the resulting dataset meets your needs.