> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omni.co/llms.txt
> Use this file to discover all available pages before exploring further.

# custom_primary_key_sql

> Defines a custom aggregation level for deduplication.

This is used to dedupe over a different aggregation level than the default behavior. For example, aggregation over an intermediate table or another key. This can be used for similar use cases to [level-of-detail calculation](/modeling/dimensions/parameters/level-of-detail).

## Syntax

```yaml theme={null}
<measure_name>:
  sql: <field>
  aggregate_type: sum_distinct_on
  custom_primary_key_sql: ${<view_name>.<field_name>}
```

## Properties

<ParamField path="measure_name" type="object[]">
  The name of the measure.

  <Expandable title="measure_name properties" defaultOpen="true">
    <ParamField path="aggregate_type" type="string">
      The type of aggregation to apply. Must be one of:

      * `sum_distinct_on`
      * `average_distinct_on`
      * `percentile_distinct_on`
      * `median_distinct_on`

      Refer to the [`aggregate_type` reference](/modeling/measures/parameters/aggregate-type) for more information about this parameter.
    </ParamField>

    <ParamField path="custom_primary_key_sql" type="string">
      A field reference that defines the key to use for deduplication, specified using `${}` syntax.
    </ParamField>
  </Expandable>
</ParamField>

## Examples

```yaml theme={null}
distinct_price:
  sql: price
  aggregate_type: sum_distinct_on
  custom_primary_key_sql: ${id_from_other_table}
```

<Tip>
  The combination of a **Custom Primary Key** and these specific aggregate types is best used in scenarios where you are aggregating a field based off of the primary key in another table.
</Tip>
