expect_table_row_count_to_equal_other_table_times_factor
How it Works
The expect_table_row_count_to_equal_other_table_times_factor test from the dbt-expectations package validates that the row count of one model equals the row count of a reference model multiplied by a constant factor. This is particularly useful for models that fan out from a parent (e.g., generating one row per metric per entity).
Steps and Conditions
- Reference Model: Specify the comparison model using
compare_model. - Factor: Define the multiplication factor.
- Execution: Both row counts are computed; the reference count is multiplied by the factor and compared.
- Outcome: Pass if counts match; fail if they differ.
Example Usage: Metric Fanout
A data team generates one row per metric per user in a user_metrics model, with 5 metrics per user. The users model has the base row count.
models:
- name: user_metrics
tests:
- dbt_expectations.expect_table_row_count_to_equal_other_table_times_factor:
compare_model: ref('users')
factor: 5If any user is missing some metrics or extra metrics are generated, the row count will deviate and the test will fail.
Interested to Learn More? Try Out the Free 14-Days Trial
One AI-native workspace to build, ship, and monitor dbt™ — without the tool sprawl.
Join industry leaders winning with DinoAI agents
Data engineers and analysts at the most AI-native startups and enterprises use Paradime's DinoAI agents everyday to become market leaders.