Symptom
- Adding two fields and one of the fields comes from the association
For example: (DatasourceA.FieldA)+(DatasourceB.FieldB) -> DatasourceB is the associated data source - Using aggregation in a Calculated Field and it's returning zero.
Environment
SAP S/4HANA Cloud Public Edition
Reproducing the Issue
- Go to Custom CDS Views app
- Preview the CDS view
- The result of calculated field is zero
Cause
Depending of the data type that are aggregated, when the value is 0 the system identified it as "Null" and all the aggregation ended up returning "Null" as well. For example X + null is then null (0 is returned).
For example, if the value of the DatasourceB.FieldB is "0/Null", no matter what DatasourceA.FieldA is, the calculated field value will be "0/Null"
Resolution
In order to resolve this issue, there's a function called coalesce that could be used.
coalesce(expression1, expression2)
It says that if expression1 is not null, expression1 is returned, otherwise expression2 is returned.
In these cases, use for example: coalesce(DatasourceA.FieldA, 0) + coalesce(DatasourceB.FieldB, 0)
See Also
Keywords
Custom CDS View, 0, calculated field, returning, calculation, zero, null , KBA , BC-SRV-APS-GKE , Generic CDS Key User Editor , Problem
SAP Knowledge Base Article - Public