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
$2,275.20158$14.40$4,928.40283$17.41$4,356.00242$18.00$2,860.20159.25$17.96$14,419.80842.25$17.12
$25,296.00120$210.80$51,962.20223$233.01$68,510.00260$263.50$72,989.50253.75$287.64$218,757.70856.75$255.33
$270.0075$3.60$1,756.80421$4.17$2,457.00546$4.50$2,512.13525.625$4.78$6,995.931567.625$4.46
$1,472.0040$36.80$11,518.40258$44.64$8,556.00186$46.00$2,196.5041.25$53.25$23,742.90525.25$45.20
$1,324.8092$14.40$7,707.60447$17.24$6,984.00388$18.00$3,957.30203.25$19.47$19,973.701130.25$17.67
   $910.0065$14.00$1,596.00114$14.00   $2,506.00179$14.00
$1,080.0090$12.00$5,880.00413$14.24$3,720.00248$15.00$30.000$30.00$10,710.00751$14.26
$421.6068$6.20$4,767.80630$7.57$3,107.75401$7.75$25.380$25.38$8,322.531099$7.57
$784.0070$11.20$2,240.00171$13.10$3,430.00245$14.00$3,925.25271.875$14.44$10,379.25757.875$13.70
$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
$128,451.404967$25.86$575,353.2021943$26.22$399,116.3912759$31.28$197,237.573981.5$49.54$1,300,158.5643650.5$29.79
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