cardinality_equality
Feb 24, 2026
·
5
min read
Uniqueness, Tables relationship
·
dbt-utils
·
Model
How it Works
The cardinality_equality test from dbt-utils™ validates that two columns (potentially from different models) have the same number of distinct values. This is useful for verifying that a transformation hasn't collapsed or expanded the cardinality of a key column unexpectedly, or for confirming cross-table consistency.
Steps and Conditions
Column Selection: Identify the column to test.
Comparison: Specify the reference model and its column using
toandfield.Execution: The distinct count of each column is computed and compared.
Outcome: Pass if the distinct counts are equal; fail if they differ.
Example Usage: Dimension Tables
A data team wants to confirm that the number of distinct product_id values in their fact_orders model matches the number of products in the dim_products dimension table.
A mismatch would indicate that orders reference products not present in the dimension table, causing broken lookups in BI tools.





