New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Calculations

empty
TotalPriceQuantityAverage PriceYear
CategoryProductName
199619971998Forecast for 1999Total Sum of TotalPriceTotal Sum of QuantityTotal Average Price
Sum of TotalPriceSum of QuantityAverage PriceSum of TotalPriceSum of QuantityAverage PriceSum of TotalPriceSum of QuantityAverage PriceSum of TotalPriceSum of QuantityAverage Price
$3,139.20218$14.40$4,928.40283$17.41$4,356.00242$18.00$3,184.20181.75$17.52$15,607.80924.75$16.88
$29,512.00140$210.80$51,962.20223$233.01$68,510.00260$263.50$74,570.50261.25$285.44$224,554.70884.25$253.95
$349.2097$3.60$1,756.80421$4.17$2,457.00546$4.50$2,541.83533.875$4.76$7,104.831597.875$4.45
$4,084.80111$36.80$11,518.40258$44.64$8,556.00186$46.00$3,176.3067.875$46.80$27,335.50622.875$43.89
$1,411.2098$14.40$7,707.60447$17.24$6,984.00388$18.00$3,989.70205.5$19.41$20,092.501138.5$17.65
$56.005$11.20$910.0065$14.00$1,596.00114$14.00$1,876.00134.375$13.96$4,438.00318.375$13.94
$1,380.00115$12.00$5,880.00413$14.24$3,720.00248$15.00$142.500$142.50$11,122.50776$14.33
$744.00120$6.20$4,767.80630$7.57$3,107.75401$7.75$146.289.375$15.60$8,765.831160.375$7.55
$1,008.0090$11.20$2,240.00171$13.10$3,430.00245$14.00$4,009.25279.375$14.35$10,687.25785.375$13.61
$2,160.00150$14.40$5,857.20346$16.93$4,734.00263$18.00$2,364.75116.875$20.23$15,115.95875.875$17.26
$168,470.506691$25.18$602,158.7023301$25.84$417,091.2414063$29.66$214,452.535465.125$39.24$1,402,172.9749520.125$28.32
BeveragesChartreuse verte
Côte de Blaye
Guaraná Fantástica
Ipoh Coffee
Lakkalikööri
Laughing Lumberjack Lager
Outback Lager
Rhönbräu Klosterbier
Sasquatch Ale
Steeleye Stout
Grand Total
Page size:

This demo shows two types of custom data calculations. Calculated fields and calculated items. Such calculated data in RadPivotGrid extends the data available directly from the Database, by providing expression or making more complex calculations.

  • The calculated field used in the demo is the "Average Price" field.
    The difference between calculated AggregateField regular AggregateField in the declaration of RadPivotGrid is the presence of CalculationDataFields and CalculationExpression properties.
    • CalculationDataFields - DataFields that the calculation is based on.
    • CalculationExpression - The expression used for calculation.
  • Calculated item is such item that do not in the database, but it is calculated by custom server side logic.
    Such items in this demo are the"Forecast for 1999" items in the group shown as part of "Year" DataField.
    To add such items you need to declarate PivotGridCalculatedItem inside CalculatedItems collection of PivotGridColumnField or PivotGridRowField
    To perform the custom calculation for given item, you will need to handle the OnItemNeedCalculation of RadPivotGrid.
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
<%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.PivotGridExamplesCSharp.Calculatons.DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
<div class="demo-container no-bg">
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadPivotGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadPivotGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
    <telerik:RadPivotGrid RenderMode="Lightweight" AllowPaging="true" OnNeedDataSource="RadPivotGrid1_NeedDataSource"
        ID="RadPivotGrid1" runat="server" ColumnHeaderZoneText="ColumnHeaderZone"
        ShowFilterHeaderZone="false" AllowFiltering="false" OnItemNeedCalculation="RadPivotGrid1_ItemNeedCalculation"
        OnCellDataBound="RadPivotGrid1_CellDataBound">
        <Fields>
            <telerik:PivotGridRowField DataField="Category">
            </telerik:PivotGridRowField>
            <telerik:PivotGridRowField DataField="ProductName">
            </telerik:PivotGridRowField>
            <telerik:PivotGridColumnField DataField="Year">
                <CalculatedItems>
                    <telerik:PivotGridCalculatedItem GroupName="Forecast for 1999"></telerik:PivotGridCalculatedItem>
                </CalculatedItems>
            </telerik:PivotGridColumnField>
            <telerik:PivotGridAggregateField DataField="TotalPrice" Aggregate="Sum" DataFormatString="{0:C}">
            </telerik:PivotGridAggregateField>
            <telerik:PivotGridAggregateField DataField="Quantity" Aggregate="Sum">
            </telerik:PivotGridAggregateField>
            <telerik:PivotGridAggregateField DataField="Average Price" CalculationDataFields="TotalPrice,Quantity" CalculationExpression="{0}/{1}" DataFormatString="{0:C}" CellStyle-Font-Italic="true">
            </telerik:PivotGridAggregateField>
        </Fields>
        <SortExpressions>
            <telerik:PivotGridSortExpression FieldName="TotalPrice" SortOrder="Descending" />
        </SortExpressions>
    </telerik:RadPivotGrid>
    </div>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance