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