cube-js/cube · error · UserError
Unsupported additional filters for measure ${sourceMeasure}
Error message
Unsupported additional filters for measure ${sourceMeasure} type ${aggType} What it means
Adding filters (addFilters) to a rolled-up measure is only supported for count, count_distinct, and count_distinct_approx aggregations, whose SQL can be safely wrapped with filter conditions. For any other aggType (string, time, boolean, number, avg, sum), the aggregation is already baked into the SQL and filters cannot be injected, so preparePatchedMeasure throws this UserError.
Source
Thrown at packages/cubejs-schema-compiler/src/adapter/BaseMeasure.ts:99
const resultFilters = source.filters ?? [];
if (addFilters.length > 0) {
switch (resultMeasureType) {
case 'sum':
case 'avg':
case 'min':
case 'max':
case 'count':
case 'count_distinct':
case 'countDistinct':
case 'count_distinct_approx':
case 'countDistinctApprox':
// ok, do nothing
break;
default:
// Can not add filters to string, time, boolean, number
// Aggregation is already included in SQL, it's hard to patch that
throw new UserError(
`Unsupported additional filters for measure ${sourceMeasure} type ${aggType}`
);
}
resultFilters.push(...addFilters);
}
const patchedFrom = this.query.cubeEvaluator.parsePath('measures', sourceMeasure);
// For view measures, `type` is `number` (aggregation is embedded in SQL)
// while `aggType` carries the real aggregation kind. We must preserve that
// distinction to avoid double-wrapping (e.g. SUM(SUM(...))).
const typeFields = source.aggType != null
? { type: source.type, aggType: resultMeasureType }
: { type: resultMeasureType };
return {
...source,View on GitHub (pinned to 7d981676b3)
Solutions
- Move the filter into the measure's own SQL definition or use a filtered measure (filters: [...] in the cube schema)
- Only use addFilters with count/count_distinct family measures
- Create a separate pre-aggregation that filters at the base-query level via timeDimension/dateJoinCondition instead
- If filtering is required on sums, define the filtered measure explicitly in the data model
Example fix
// before
{ measure: 'Orders.totalAmount', aggType: 'sum', addFilters: [{ member: 'Orders.status', operator: 'equals', values: ['shipped'] }] }
// after (schema)
totalShipped: { type: 'sum', sql: 'amount', filters: [{ sql: "${Orders}.status = 'shipped'" }] } Defensive patterns
Strategy: try-catch
Validate before calling
function checkRollupFilters(m) {
const filterable = ['count','count_distinct','count_distinct_approx'];
if (m.addFilters?.length && !filterable.includes(m.aggType)) {
throw new Error(`addFilters not supported for ${m.aggType} measure ${m.measure}`);
}
} Try / catch
try {
await cubeApi.load(query);
} catch (e) {
if (e.message.startsWith('Unsupported additional filters for measure')) {
console.error('Move filters into a schema-level filtered measure:', e.message);
}
throw e;
} Prevention
- Use cube schema filters: [...] for filtered sum/avg measures
- Restrict addFilters to count-family measures
- Lint rollup configs for measure/filter combinations
When it happens
Trigger: Requesting a rollup/patch that supplies additional filters for a non-count measure — e.g. query.rollup with { measure: 'Orders.totalAmount', aggType: 'sum', addFilters: [...] } or filtered rollup references on avg/sum measures.
Common situations: Building filtered pre-aggregations over sum/avg measures; UIs letting users add segment filters to any measure; automated rollup generators attaching filters indiscriminately.
Related errors
- Unsupported measure type replacement for ${sourceMeasure}: $
- Only fixed rolling windows are supported by Cube Store but g
- Unknown pre-aggregation type '${preAggregation.type}' in '${
- compareDateRange can only exist for one timeDimension
- Expected one parameter but nothing found
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/38d3df53d0b9840b.
Report an issue: GitHub.