orders
and customers
are connected: custkey
of orders
to custkey
of customers
. custkey
is the granularity key of customers
.
fact_sales
: a fact table tracking order transactions that has a foreign key customer_id
dim_customer
: a dimension table holding current customer information that has a primary key customer_id
dim_customer
dimension table only keeps the latest customer attributes (e.g., latest region), and does not track history.It is sometimes called an SCD 1 type table.customer_id
field from both sides.fact_sales
to dim_customer
fact_sales
(Fact Table)
order_id | customer_id | order_date | amount |
---|---|---|---|
5001 | 101 | 2021-06-10 | 250 |
5002 | 101 | 2023-01-12 | 300 |
5003 | 102 | 2022-07-22 | 450 |
dim_customer
(Dimension Table)
customer_id | name | region |
---|---|---|
101 | Alice Smith | West |
102 | Bob Johnson | North |
order_id | customer_id | order_date | amount | name | region |
---|---|---|---|---|---|
5001 | 101 | 2021-06-10 | 250 | Alice Smith | West |
5002 | 101 | 2023-01-12 | 300 | Alice Smith | West |
5003 | 102 | 2022-07-22 | 450 | Bob Johnson | North |
one-to-many
or many-to-one
cardinality.ƒact_orders
with dim_customer
using a condition
ƒact_orders
with dim_customer
over a specific time range
ƒact_orders
with dim_customer
using a field which is not a key of dim_customer
fact_orders
is connected with dim_region
dimension
Connect ƒact_orders
with dim_customer
using a field from dim_region
fact_sales
: a fact table tracking order transactions that has a foreign key customer_id
dim_customer
: a dimension table tracking customer information over time (SCD Type 2). It has multiple entries
per customer_id
with validity ranges.valid_from
and valid_to
:
fact_sales
to dim_customer
fact_sales
(Fact Table)
order_id | customer_id | order_date | amount |
---|---|---|---|
5001 | 101 | 2021-06-10 | 250 |
5002 | 101 | 2023-01-12 | 300 |
5003 | 102 | 2022-07-22 | 450 |
dim_customer
(SCD2 Dimension Table)
customer_id | customer_sk | name | region | valid_from | valid_to |
---|---|---|---|---|---|
101 | 1 | Alice Smith | East | 2021-01-01 | 2022-03-01 |
101 | 2 | Alice Smith | West | 2022-03-01 | 9999-12-31 |
102 | 3 | Bob Johnson | North | 2021-05-15 | 9999-12-31 |
dim_customer
is not customer_id
(which is repeating across ranges), but rather a surrogate key (customer_sk
)
valid_from
/ valid_to
define the row’s effective period.Also note that valid_to here is an infinity date (9999-12-31). In some settings it is used as NULL instead, in which case can
adjust the join condition accordingly.order_id | customer_id | order_date | amount | name | region |
---|---|---|---|---|---|
5001 | 101 | 2021-06-10 | 250 | Alice Smith | East |
5002 | 101 | 2023-01-12 | 300 | Alice Smith | West |
5003 | 102 | 2022-07-22 | 450 | Bob Johnson | North |
customers.name
), while filtering on another
entity (parts.brand = 'Brand#55'
) ? Would you get the list of customers that had orders of parts of that brand,
or would you get all customers?
The answer is based on whether a filter from parts
“flows” the path of parts
→ order_lines
→ orders
→ customers
or not. Each relationship can control in what directions can filters pass through (“cross-filter”).
Following settings are supported (given a 1:many relationship):
Join Type (Between many side to 1 side) | Cross filtering options | Default |
---|---|---|
INNER, RIGHT | Both, One-to-many | Both |
LEFT, OUTER | Both, One-to-many, Many-to-one, None | Both |
both
cross-filtering
and LEFT
join type.
In that case every filter used by the user will propagate to any entity regardless on where it comes from.
both
cross-filtering and INNER
join type.
In that case every filter used by the user will propagate to any entity regardless on where it comes from.
Additionally, any values that do not exist in a dimension will be removed from the fact when joined.
one-to-many
cross- filtering and RIGHT
join direction.
In that all the values of that dimension always present in a group by, and can filter the fact.
none
and OUTER
so no actions on either fact or dimension impact values directly, and only filter the metric.
target_entity
: entity to connect toconnection
: a list of fields for a join condition. Must fully cover the primary key of the entity on the “one” side of the relation.connection_expr
: a custom join expression, if connection
is not set. The sql
expression may only use attributes.rel_type
: logical direction of the relationshiprel_join_type
(optional): the type of default join to applycross_filtering
(optional): the cross-filtering configuration to apply