Medium severityquery
Power BI Refresh Error:
1111
What does this error mean?
An aggregate function (SUM, COUNT, MAX, etc.) is used in a WHERE clause instead of a HAVING clause.
Common causes
- 1Using WHERE COUNT(*) > 10 instead of HAVING COUNT(*) > 10
- 2Aggregate functions in a subquery WHERE condition referencing the outer query incorrectly
- 3dbt model uses aggregate in a WHERE filter instead of HAVING
How to fix it
- 1Step 1: Move aggregate conditions from WHERE to HAVING: `SELECT col, COUNT(*) FROM t GROUP BY col HAVING COUNT(*) > 10;`
- 2Step 2: If filtering on an aggregated subquery result, use a derived table: `SELECT * FROM (SELECT col, COUNT(*) AS cnt FROM t GROUP BY col) sub WHERE sub.cnt > 10;`
- 3Step 3: In dbt, review any WHERE clauses in grouped models for misplaced aggregates.
Frequently asked questions
Official documentation: https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html