Possible to have a weighted average Summary Row value?

Hi,

I have an sfDataGrid with some stock trades, and I am grouping the rows. In the Summary Row, I want to be able to put the weighted average price of the trades (SUM(tradeSize*tradePrice) / SUM(tradeSize)) in same column as the Price.

Is there a way to achieve this?



1 Reply

VS Vijayarasan Sivanandham Syncfusion Team July 28, 2022 03:07 PM UTC

Hi Lorenzo,

Solution 1:

Your requirement to display the average value for the price column in SfDataGrid can be achieved by using GridSummaryColumn.SummaryType property and use the built-in function in GridSummaryColumn.Format. Please refer to the below code snippet,

<syncfusion:SfDataGrid.CaptionSummaryRow>

<syncfusion:GridSummaryRow ShowSummaryInRow="False">

<syncfusion:GridSummaryRow.SummaryColumns>

<syncfusion:GridSummaryColumn Name="PriceAmount"

Format="'{Average:c} '"

MappingName="UnitPrice"

SummaryType="DoubleAggregate" />

syncfusion:GridSummaryRow.SummaryColumns>

syncfusion:GridSummaryRow>

syncfusion:SfDataGrid.CaptionSummaryRow>

<syncfusion:SfDataGrid.GroupSummaryRows>

<syncfusion:GridSummaryRow ShowSummaryInRow="False">

<syncfusion:GridSummaryRow.SummaryColumns>

<syncfusion:GridSummaryColumn Name="PriceAmount"

Format="'{Average:c} '"

MappingName="UnitPrice"

SummaryType="DoubleAggregate" />

syncfusion:GridSummaryRow.SummaryColumns>

syncfusion:GridSummaryRow>

syncfusion:SfDataGrid.GroupSummaryRows>


UG Link: https://help.syncfusion.com/wpf/datagrid/summaries#aggregate-types

Solution 2:

You can calculate the summary based on custom logic using GridSummaryColumn.CustomAggregate property. For more information related to CustomAggregate, please refer to the below user guide documentation link,


UG Link: https://help.syncfusion.com/wpf/datagrid/summaries#custom-summaries

Please find the sample in the attachment and let us know if you have any concerns in this.


Regards,

Vijayarasan S


Attachment: SfDataGridDemo_5d5d4a2c.zip


Loader.
Up arrow icon