This is a migrated thread and some comments may be shown as answers.

Aggregates handle nulls inconsistently?

1 Answer 13 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
SEAN
Top achievements
Rank 1
SEAN asked on 07 Nov 2011, 12:59 AM
I have found that if I use a Count aggregate or an Average aggregate on a nullable column (the property I'm binding to in my model is a nullable decimal - decimal?) I get inconsistent results when there are nulls in the data. The Count includes all rows, even those that have null in the column value, but the Average excludes the nulls. So for example if I have four rows with the values 1, 8, null and 3, then the Count is 4, and the Average is 4 (12 divided by 3). I think the Average is correct and the Count is wrong, the Count should exclude nulls like the Average does. This would be consistent with SQL handling of nulls in aggregates.

I am managing to get the count excluding nulls now by dividing the Sum by the Average so please don't change the Average behavior because then there will be no way to get the count excluding nulls! 

Sean

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 08 Nov 2011, 06:03 PM
Hello Sean,

The behavior you have described is by design. The Count function includes null values in the calculation as it will look a bit strange if there is a single item in the grid which have null value and the count shows zero meaning that there are no items. Having this in mind, the count function behaves more like MSSQL's COUNT(*).

Regards,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
SEAN
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or