# Model Multi - Fact

**URL:** <https://discuss.google.dev/t/model-multi-fact/113387>\
**Category:** Looker\
**Tags:** lookml\
**Created:** [March 31, 2021, 4:13pm UTC](https://discuss.google.dev/t/model-multi-fact/113387 "2021-03-31T16:13:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [March 31, 2021, 4:13pm UTC](https://discuss.google.dev/t/model-multi-fact/113387/1 "2021-03-31T16:13:39Z")

</div>

Hello all, I’m a newbie. I need to realize a model that link together two or more fact tables.

For example Movements and Orders.

Both the facts have in common the SKU Dimension, and each have one or more specific dimensions:

| MOVEMENTS\_TBL |
| --- |
| MOV\_ID |
| MOV\_DATE |
| MOV\_REASON\_COD |
| SKU\_COD |
| MOV\_QTY |

| ORDERS\_TBL |
| --- |
| ORD\_ID |
| ORD\_DATE |
| ORD\_REASON\_COD |
| SKU\_COD |
| ORD\_QTY |

| SKU\_TBL |
| --- |
| SKU\_COD |
| SKU\_DESCR |
| BRAND\_COD |
| BRAND\_DES |

What are the best way to proceed?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![mathias\_luyten](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/mathias_luyten/32/44388_2.png) [@mathias\_luyten](https://discuss.google.dev/u/mathias_luyten)\
**Post date:** [April 2, 2021, 2:25pm UTC](https://discuss.google.dev/t/model-multi-fact/113387/2 "2021-04-02T14:25:35Z")

</div>

At which granularity do you want to create that join? And how are movements and orders related to each other?

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [April 2, 2021, 2:41pm UTC](https://discuss.google.dev/t/model-multi-fact/113387/3 "2021-04-02T14:41:14Z")

</div>

As you can see, both tables have in common only the column SKU\_COD.

The goal I want to reach is a dashboard where I can mix Mov Qty and Ord Qty together, maybe at different level of details.

For example if in the visualization there will be Brand Cod, Mov Qty and Ord Qty, I’d love to see the following querys:

```auto
INSERT INTO TEMP_TBL1
select brand_cod, sum(mov_qty) as MOV_QTY
from MOVEMNTS_TBL mov
left join sku_tbl sku
on mov.sku_cod=sku_tbl.sku_cod
group by brand cod;

INSERT INTO TEMP_TBL2
select brand_cod, sum(ord_qty) as ORD_QTY
from ORDERS_TBL ord
left join sku_tbl sku
on ord.sku_cod=sku_tbl.sku_cod
group by brand_cod
;
select brand_cod, MOV_QTY, ORD_QTY
from TBL1
FULL OUTER JOIN TBL2
ON TBL1.BRAND_COD=TBL2.BRAND_COD

```

Second Example: sku\_cod, Mov Qty and Ord Qty

```auto
INSERT INTO TEMP_TBL1
select sku_cod, sum(mov_qty) as MOV_QTY
from MOVEMNTS_TBL mov
group by sku_cod;

INSERT INTO TEMP_TBL2
select sku_cod, sum(ord_qty) as ORD_QTY
from ORDERS_TBL ord
group by sku_cod
;
select sku_cod, MOV_QTY, ORD_QTY
from TBL1
FULL OUTER JOIN TBL2
ON TBL1.sku_cod=TBL2.sku_cod

```

How can I reach that goal?

Thanks.

Marco

---

<div class="post-metadata">

**Author:** ![mathias\_luyten](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/mathias_luyten/32/44388_2.png) [@mathias\_luyten](https://discuss.google.dev/u/mathias_luyten)\
**Post date:** [April 2, 2021, 3:01pm UTC](https://discuss.google.dev/t/model-multi-fact/113387/4 "2021-04-02T15:01:36Z")

</div>

Have you tried the SQL runner in Looker?

You could execute that query there and save the result as a derived table, which you can add as a view in your Looker project.

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [April 2, 2021, 3:05pm UTC](https://discuss.google.dev/t/model-multi-fact/113387/5 "2021-04-02T15:05:08Z")

</div>

yes, I tried it. I thought that Looker was able to automatically generate the above queries, once the sku Dimension was joined to both facts Tables.

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [June 18, 2021, 4:14pm UTC](https://discuss.google.dev/t/model-multi-fact/113387/6 "2021-06-18T16:14:34Z")

</div>

​ hey @Marco , I’m curious, is derived table worked for you? ​

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [July 11, 2021, 3:59pm UTC](https://discuss.google.dev/t/model-multi-fact/113387/7 "2021-07-11T15:59:33Z")

</div>

Hi Marco,  
I am also curious to know if the derived table approach worked for you.

I am facing the same challenge which I overcame by creating a big denormalized fact table
