MetricSign
EN|NLRequest Access
Medium severitysql

Power BI Refresh Error:
SCHEMA_MISMATCH_FOR_UNION

What does this error mean?

A UNION or UNION ALL query failed because the column count or data types of the two result sets are incompatible. Spark SQL requires that both sides of a UNION have the same number of columns and compatible types.

Common causes

  • 1One branch of the UNION has more or fewer columns than the other
  • 2A column was added to one source table but not to the corresponding SELECT in the other branch
  • 3Implicit type promotion fails because one side returns STRING and the other returns STRUCT or ARRAY
  • 4A wildcard SELECT * was used in one branch and the underlying table schema changed
  • 5A CTE or subquery returned a different number of columns after a schema change

How to fix it

  1. 1Count the output columns in each UNION branch — they must be equal.
  2. 2Cast columns to a common type: CAST(col AS STRING) or use COALESCE(col, CAST(NULL AS <type>)) as a placeholder.
  3. 3Replace SELECT * with explicit column lists in both branches to make schema dependencies explicit.
  4. 4Run each branch individually to verify its column count and types before combining with UNION.
  5. 5If one branch intentionally omits a column, add a NULL literal with the correct type: NULL::INT AS column_name.

Frequently asked questions

Does UNION ALL have the same requirement as UNION?

Yes. Both UNION and UNION ALL require matching column counts and compatible types. UNION ALL just skips the deduplication step.

How do I handle a column that only exists in one data source?

Add a NULL placeholder in the branch where the column is absent: SELECT col1, col2, NULL AS col3 FROM source_a UNION ALL SELECT col1, col2, col3 FROM source_b.

Other sql errors