expect_table_aggregation_to_equal_other_table
How it Works
The expect_table_aggregation_to_equal_other_table test from the dbt-expectations package validates that an aggregate computation (e.g., sum, count, avg) on a column in one model matches the corresponding aggregate from a reference model. This is ideal for cross-table reconciliation checks.
Arguments include expression (the aggregation function), compare_model, and compare_expression for the reference side.
Steps and Conditions
- Define Aggregation: Specify the column and aggregation expression.
- Reference Model: Provide the comparison model and its aggregation expression.
- Execution: Both aggregations are computed and compared.
- Outcome: Pass if the aggregations match; fail if they differ.
Example Usage: Finance
A finance team wants to ensure the total revenue in the revenue_summary model matches the sum of individual line items in the invoice_line_items model.
models:
- name: revenue_summary
tests:
- dbt_expectations.expect_table_aggregation_to_equal_other_table:
expression: sum(total_revenue)
compare_model: ref('invoice_line_items')
compare_expression: sum(line_amount)A mismatch indicates the summary model is not correctly rolling up from its source, requiring investigation into the transformation logic.
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.