# Why am I getting the error: “Joins fan out the data without a primary key”?

**URL:** <https://community.omni.co/t/why-am-i-getting-the-error-joins-fan-out-the-data-without-a-primary-key/37>\
**Category:** Errors\
**Tags:** primary-key\
**Created:** [April 10, 2024, 11:51pm UTC](https://community.omni.co/t/why-am-i-getting-the-error-joins-fan-out-the-data-without-a-primary-key/37 "2024-04-10T23:51:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![conner](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/conner/32/11_2.png) [@conner](https://community.omni.co/u/conner)\
**Post date:** [April 10, 2024, 11:51pm UTC](https://community.omni.co/t/why-am-i-getting-the-error-joins-fan-out-the-data-without-a-primary-key/37/1 "2024-04-10T23:51:15Z")

</div>

_ **How to fix the error** _

If you define your table’s primary key, that should resolve the error! A table’s **primary key** is a column that contains a unique identifier per row — usually, it’s an `ID` column.

There are 2 ways to define your primary key:

1. **Defining your primary key through the UI**  
Omni makes it easy to define a primary key by right-clicking the field in the field picker and hitting Modeling \> Primary Key:

1. **Defining your primary key through the model IDE**  
Navigate to the table in your model (you can do this in either your shared or workbook, depending on if you’d like this to be defined for your entire org or just this workbook). Add the `primary_key: true` parameter to the appropriate dimension:

_ **Advanced** _: If your table has a compound primary key (comprised of a few different fields), you can add the `custom_compound_primary_key_sql` parameter to your view file. For example:

```auto
custom_compound_primary_key_sql: [id, date]

```

_ **Why you’re getting this error** _

You may be trying to calculate an aggregation (sum, count, average, etc.) on a table that’s being “fanned out” by a join. This happens when you’re joining two tables, and one row in the first table gets joined onto multiple rows in the other table. For example, if table A is an `orders` table, and table B is an `order_items` table, then joining the tables on `order_id` will fan out the `orders` table since many items in `order_items` match to the same order in `orders`.

Omni uses a method called _symmetric aggregates_ to prevent from inadvertently miscalculating aggregations (sums, counts, averages, etc.) when a table is being fanned out. Symmetric aggregates can get pretty complex, but here’s the main idea: before Omni calculates an aggregation on a fanned out table, it’ll look at that table’s **primary key** — its unique ID per row — to ensure it’s not double-counting values in the aggregation.

If you haven’t defined a **primary key** on your fanned out table, Omni won’t know how to calculate aggregations correctly, so it’ll throw this error to protect you from an incorrect result.
