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

Customizing aggregate functions

1 Answer 275 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bernhard
Top achievements
Rank 1
Bernhard asked on 29 Mar 2017, 02:44 PM

Hi.

In my grid I've got some columns with double values. Some of the values might be null values or Double.NaN resp.
However, in a summary row I need value counts, average and standard deviation of the values - excluding the null values!
How can I customize the grid aggregate functions to achieve this?
I experimented with GridViewSummaryItem.AggregateExpression a bit, but I don't know how to formulate an If-Condition to skip the null value row.
My code so far looks like this:

        Dim avg As New GridViewSummaryRowItem()
        Dim count As New GridViewSummaryRowItem()
        Dim stdev As New GridViewSummaryRowItem()
        For col As Integer = 2 To table.Columns.Count - 1
            Dim row_cnt As New GridViewSummaryItem()
            row_cnt.Name = table.Columns(col).ColumnName
            row_cnt.Aggregate = GridAggregateFunction.Count
            row_cnt.FormatString = "# {0}"
            count.Add(row_cnt)
            Dim row_avg As New GridViewSummaryItem()
            row_avg.Name = table.Columns(col).ColumnName
            row_avg.Aggregate = GridAggregateFunction.Avg
            row_avg.FormatString = "Ø {0:F4}"
            avg.Add(row_avg)
            Dim row_stdev As New GridViewSummaryItem()
            row_stdev.Name = table.Columns(col).ColumnName
            row_stdev.Aggregate = GridAggregateFunction.StDev
            row_stdev.FormatString = "σ {0:F4}"
            stdev.Add(row_stdev)
        Next
        grd_data_.SummaryRowsBottom.Add(count)
        grd_data_.SummaryRowsBottom.Add(avg)
        grd_data_.SummaryRowsBottom.Add(stdev)

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Mar 2017, 10:11 AM
Hello Bernhard, 

Thank you for writing.  

Please refer to the last section in the following help article which demonstrates how to create a custom GridViewSummaryItem and override its Evaluate method in order to control how exactly the result is calculated: http://docs.telerik.com/devtools/winforms/gridview/rows/summary-rows
 
You can use a similar approach and skip the null values.

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Bernhard
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or