TanStack/table · warning

aggregationFn id '${id}' for column '${column.id}' is duplic

Error message

aggregationFn id '${id}' for column '${column.id}' is duplicated

What it means

When a column's `aggregation` option is an array of aggregation-fn ids or descriptors, each entry must have a unique stable id. During resolution in column_getAggregationFns, any id that appears more than once in the array is dropped (its aggregationFn resolves to undefined) and this dev warning is fired, because duplicated ids would collide in the aggregated result object and make output ambiguous.

Source

Thrown at packages/table-core/src/features/row-aggregation/rowAggregationFeature.utils.ts:308

  for (let i = 0; i < option.length; i++) {
    const item = option[i]
    const id =
      typeof item === 'string'
        ? item
        : isAggregationFnDescriptor(item)
          ? item.id
          : undefined

    if (id === undefined) {
      warn(
        `aggregationFn at index ${i} for column '${column.id}' needs a stable id`,
      )
      resolved.push({ aggregationFn: undefined, id: undefined })
      continue
    }

    if (ids[id]! > 1) {
      warn(`aggregationFn id '${id}' for column '${column.id}' is duplicated`)
      resolved.push({ aggregationFn: undefined, id })
      continue
    }

    const ref = isAggregationFnDescriptor(item) ? item.aggregationFn : item
    resolved.push({
      aggregationFn: resolveAggregationFn(column, ref),
      id,
    })
  }

  return finish(resolved)
}

function getSubRowResult(
  subRowValue: unknown,
  isMultiple: boolean,
  id: string | undefined,

View on GitHub (pinned to d01c01bedb)

Solutions

  1. Give every entry in the aggregation array a unique id (rename the duplicate descriptor's `id`).
  2. If you need the same aggregation logic twice, wrap it in a descriptor with a distinct id, e.g. {id: 'sumRows', aggregationFn: 'sum'}.
  3. Merge or drop the redundant aggregation entry if both do the same job.
  4. Read the resolved value by its unique id instead of relying on positional duplicates.

Example fix

// before
aggregation: ['sum', 'sum']

// after
aggregation: ['sum', 'mean']
// or with descriptors:
aggregation: [
  { id: 'sumRows', aggregationFn: 'sum' },
  { id: 'sumLeafRows', aggregationFn: customLeafSum },
]
Defensive patterns

Strategy: validation

Validate before calling

function assertUniqueAggregationIds(aggregation) {
  const ids = aggregation
    .map((a) => (typeof a === 'string' ? a : a?.id))
    .filter((id) => id !== undefined)
  const dupes = ids.filter((id, i) => ids.indexOf(id) !== i)
  if (dupes.length) throw new Error(`Duplicate aggregation ids: ${[...new Set(dupes)].join(', ')}`)
}
assertUniqueAggregationIds(columnDef.aggregation ?? [])

Type guard

function hasUniqueAggregationIds(option) {
  if (!Array.isArray(option)) return true
  const ids = option
    .map((a) => (typeof a === 'string' ? a : a?.id))
    .filter((id) => id !== undefined)
  return new Set(ids).size === ids.length
}

Prevention

When it happens

Trigger: Setting `columnDef.aggregation` to an array that repeats the same string id, e.g. `['sum', 'sum']`, or two descriptors with the same `id`, e.g. `[{id: 'agg', aggregationFn: fnA}, {id: 'agg', aggregationFn: fnB}]`. Built-in id strings like 'sum', 'mean', 'count' are also checked for duplicates.

Common situations: Copy-pasting an aggregation entry and forgetting to change its id; combining a string id with a descriptor that carries the same id; generating the aggregation array programmatically and reusing a key; extending built-ins like 'count' twice for different row scopes.

Related errors


AI-assisted analysis of TanStack/table@d01c01bedb (2026-08-28). Data as JSON: /api/errors/7903aa74c1b97061. Report an issue: GitHub.