Skip to content

Power BI Direct Query Cannot Aggregate Nullable Columns #488

@slabko

Description

@slabko

Power BI converts numeric types, such as Int32, into Decimal before running aggregate functions like SUM.

For example, to get the sum of all values in the volume column from the trades table, Power BI generates the following query:

SELECT sum(CAST(volume AS Decimal)) FROM trades;

This is likely done to avoid integer overflow, as Decimal typically supports a much larger range of values.

The Decimal type comes from SQLGetTypeInfo—specifically, it is the first type that matches ODBC's SQL_DECIMAL. Normally, SQL databases allow converting NULL to any type, because most types, including Decimal, are nullable. However, in the case of ClickHouse, this causes an issue if the volume column contains NULL values.

ClickHouse does not allow converting NULL to Decimal, only to Nullable(Decimal). Therefore, the query above results in an error, even though Power BI does see any problems with the generated query.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions