Category / Section
How to handle null values in aggregated expressions
Published:
When creating expressions, it is common to encounter issues due to null values in the columns. To overcome this issue, you can handle a condition while creating SUM expressions for the columns containing null values.
Syntax
To handle null values in expressions, use the following syntax:
IF(SUM([Column name]) IS NULL, 0, SUM([Column name]))
Example
Consider the following sample expression:
IF(SUM([Balance]) IS NULL, 0, SUM([Balance])) + IF(SUM([Credited]) IS NULL, 0, SUM([Credited])) + IF(SUM([Income]) IS NULL, 0, SUM([Income]))
This expression applicable for all data sources except Microsoft SQL Server Analysis Services (SSAS).
This expression checks if the sum of each column is null. If it is, the expression returns 0; otherwise, it returns the sum of the column.
Output
The output of the expression will be the sum of the non-null values in the specified columns.