# Building a Kimball dimensional model with dbt

**URL:** <https://discourse.getdbt.com/t/building-a-kimball-dimensional-model-with-dbt/7940>\
**Category:** In-Depth Discussions\
**Tags:** devblog\
**Created:** [April 21, 2023, 1:57am UTC](https://discourse.getdbt.com/t/building-a-kimball-dimensional-model-with-dbt/7940 "2023-04-21T01:57:38Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![jonathanneo](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jonathanneo/32/2626_2.png) [@jonathanneo](https://discourse.getdbt.com/u/jonathanneo)\
**Post date:** [August 8, 2023, 2:11pm UTC](https://discourse.getdbt.com/t/building-a-kimball-dimensional-model-with-dbt/7940/6 "2023-08-08T14:11:58Z")

</div>

Hey @Koen, thanks for your question. The way I would handle records in the fact table that don’t match to a record in the dimension table is through the method that @josh suggested in his post [here](https://discourse.getdbt.com/t/how-do-you-deal-with-missing-dimensions-for-foreign-keys/1274/2).

So, let’s say our dimension table is `dim_user`, and we have the following columns:

- `customer_id`
- `customer_key` (the surrogate key, created by using `hash(customer_id)`
- `customer_name`

In the dbt model used to generate `dim_user`, I would add a row (using `union all`) for the following record:

```sql
select 
  -1 as customer_id,  
  hash(-1) as customer_key, 
  'Unknown Customer' as customer_name 

```

Then from the fact table (e.g. `fact_sales`), I will try to generate a surrogate key that matches `dim_user`.

```sql
select 
  sale_id, 
  price, 
  quantity, 
  hash(coalesce(customer_id, -1)) as customer_key -- if customer_id is null, -1 will be used instead. 
from 
  {{ ref('staging_sales') }} 

```

This way, the fact table will reference a customer with the customer name `Unknown Customer` instead of `null` which might cause confusion.

---

_[View the full topic](https://discourse.getdbt.com/t/building-a-kimball-dimensional-model-with-dbt/7940)._
