{"record":{"id":"5f2f22eb15593c69","repo":"cube-js/cube","slug":"measure-filters-aren-t-allowed-in-ungrouped-query","errorCode":null,"errorMessage":"Measure filters aren't allowed in ungrouped query","messagePattern":"Measure filters aren't allowed in ungrouped query","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/adapter/BaseQuery.js","lineNumber":626,"sourceCode":"        this.timeDimensions.filter(m => !!m.granularity)\n          .map(m => [m.unescapedAliasName(), `${m.dimension}.${m.granularity}`])\n      )\n    );\n  }\n\n  initUngrouped() {\n    this.ungrouped = this.options.ungrouped;\n    if (this.ungrouped) {\n      if (!this.options.allowUngroupedWithoutPrimaryKey && this.join) {\n        const cubes = R.uniq([this.join.root].concat(this.join.joins.map(j => j.originalTo)));\n        const primaryKeyNames = cubes.flatMap(c => this.primaryKeyNames(c));\n        const missingPrimaryKeys = primaryKeyNames.filter(key => !this.dimensions.find(d => d.dimension === key));\n        if (missingPrimaryKeys.length) {\n          throw new UserError(`Ungrouped query requires primary keys to be present in dimensions: ${missingPrimaryKeys.map(k => `'${k}'`).join(', ')}. Pass allowUngroupedWithoutPrimaryKey option to disable this check.`);\n        }\n      }\n      if (this.measureFilters.length) {\n        throw new UserError('Measure filters aren\\'t allowed in ungrouped query');\n      }\n    }\n  }\n\n  get subQueryDimensions() {\n    // eslint-disable-next-line no-underscore-dangle\n    if (!this._subQueryDimensions) {\n      // eslint-disable-next-line no-underscore-dangle\n      this._subQueryDimensions = this.collectFromMembers(\n        false,\n        this.collectSubQueryDimensionsFor.bind(this),\n        'collectSubQueryDimensionsFor'\n      );\n    }\n    // eslint-disable-next-line no-underscore-dangle\n    return this._subQueryDimensions;\n  }\n","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js#L608-L644","documentation":"Measure filters are predicates on aggregated values (having-style). Ungrouped queries return raw rows with no aggregation, so filtering on a measure is meaningless there; initUngrouped rejects such queries with this UserError.","triggerScenarios":"A query with ungrouped mode whose filters reference a measure (extractDimensionsAndMeasures pushes {measure: ...} entries, landing in measureFilters), e.g. filter on 'Orders.count' in a row-level query.","commonSituations":"Reusing the same filter set for grouped and ungrouped views; UIs that let users filter by metrics while the query is in raw-row drill-down mode.","solutions":["Remove measure filters from the ungrouped query","Convert the query to grouped (drop ungrouped/raw mode) if metric filtering is needed","Filter on dimensions or segments instead in ungrouped mode"],"exampleFix":"// before\n{ ungrouped: true, dimensions: ['Orders.status'], filters: [{ member: 'Orders.count', operator: 'gt', values: [5] }] }\n// after\n{ ungrouped: true, dimensions: ['Orders.status'], filters: [{ member: 'Orders.status', operator: 'equals', values: ['shipped'] }] }","handlingStrategy":"validation","validationCode":"function stripMeasureFilters(query, isMeasure) {\n  if (query.ungrouped) {\n    query.filters = (query.filters || []).filter(f => !isMeasure(f.member || f.dimension));\n  }\n  return query;\n}\nstripMeasureFilters(query, knownMeasureSet.has.bind(knownMeasureSet));","typeGuard":null,"tryCatchPattern":"try {\n  await cubeApi.load(query);\n} catch (e) {\n  if (/Measure filters aren't allowed in ungrouped/.test(e.message)) {\n    throw new Error('Remove measure filters or switch to a grouped query');\n  }\n  throw e;\n}","preventionTips":["Keep separate filter sets for grouped vs ungrouped views","In filter UIs, disable measure options when the query is ungrouped","Filter by dimensions/segments only in raw-row queries"],"tags":["ungrouped","filters","measures"],"backgroundTag":"measure-filter-in-ungrouped-query","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}