dashboard-115920-common-features-advanced-analytics-window-calculations-creating-window-calculations.md
The Dashboard Designer allows you to add a window calculation for numeric measures. To do this, invoke the data item menu and select the required calculation type.
The image above shows a calculation menu of the Pivot dashboard item. The following items are available.
Note
Note that the list of available items in this menu can be changed by the Dashboard Designer dynamically. For instance, if the Pivot dashboard item does not contain dimensions in the Rows section, menu items related to rows will be disabled.
The Running Total calculation can be used to compute a cumulative total for the specified measure across a window. For example, the Grid below displays cumulative sales across all quarters.
The Customize Calculation dialog provides the following settings for the Running Total calculation.
The Moving calculation uses neighboring values to calculate a total. For example, the Grid below shows a moving average across all quarters.
The Customize Calculation dialog provides the following settings for the Moving calculation.
The Difference calculation can be used to compute the difference between measure values across a window. For example, the Grid below shows absolute differences between quarterly sales.
The Customize Calculation dialog provides the following settings for the Difference calculation.
A calculation is used to compute a percentage of the total for the specified measure across a window. For example, the Grid below shows a contribution of individual quarterly sales to total sales.
The Customize Calculation dialog provides the following settings for the Percent of Total calculation.
Use the Rank calculation to compute rankings for the specified measure across a window. For example, the Grid below shows a ranking of sales for individual quarters.
The Customize Calculation dialog provides the following settings for the Rank calculation.
Use Expression to specify a custom calculation by adding the required calculation functions inside the measure expression.
Click the Edit in Expression Editor button to invoke the Expression Editor and specify the required expression.
The Expression type provides the Calculate along option that specifies a window and direction used to calculate differences. Note that this option is in effect if the expression contains a calculation function.
To apply a calculation to values of the required measure, perform the following steps.
The code snippet adds a new measure to the Pivot dashboard item and specifies a window calculation to compute the difference between measure values across a window. The calculation is performed along columns of the Pivot dashboard item.
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
// ...
PivotDashboardItem pivotItem = dashboardViewer1.Dashboard.Items[pivotItemName] as PivotDashboardItem;
if (pivotItem != null)
{
Measure extendedPrice = new Measure("Extended Price")
{
Name = "Diff",
ShowGrandTotals = false
};
PivotWindowDefinition pivotWindowDefinition = new PivotWindowDefinition();
pivotWindowDefinition.DefinitionMode = PivotWindowDefinitionMode.Columns;
extendedPrice.WindowDefinition = pivotWindowDefinition;
extendedPrice.Calculation = new DifferenceCalculation() { DifferenceType = DifferenceType.Absolute };
pivotItem.Values.Add(extendedPrice);
}
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
' ...
Dim pivotItem As PivotDashboardItem = TryCast(dashboardViewer1.Dashboard.Items(pivotItemName), PivotDashboardItem)
If pivotItem IsNot Nothing Then
Dim extendedPrice As New Measure("Extended Price") With { _
.Name = "Diff", _
.ShowGrandTotals = False _
}
Dim pivotWindowDefinition As New PivotWindowDefinition()
pivotWindowDefinition.DefinitionMode = PivotWindowDefinitionMode.Columns
extendedPrice.WindowDefinition = pivotWindowDefinition
extendedPrice.Calculation = New DifferenceCalculation() With {.DifferenceType = DifferenceType.Absolute}
pivotItem.Values.Add(extendedPrice)
End If
| API | Description |
|---|---|
| Measure.Calculation | Gets or sets a calculation applied to values of the current measure. |
| Measure.WindowDefinition | Gets or sets the window definition used to apply a calculation to values of the current measure. |
| Measure.Expression | Gets or sets the expression for the current measure. |
| Name | Description |
|---|---|
| RunningTotalCalculation | A running total calculation that is used to compute a cumulative total for the specified measure across a window. |
| MovingCalculation | A moving calculation that is computed for the specified measure across a window. |
| DifferenceCalculation | A difference calculation that is used to compute the difference between measure values across a window. |
| PercentOfTotalCalculation | A calculation that is used to compute a percent of the total for the specified measure across a window. |
| RankCalculation | A rank calculation that is used to compute rankings for the specified measure across a window. |
| MeasureCalculation | Serves as the base class for classes that are measure calculations allowing you to apply specific computations to Measure values that are related to the currently processed value. |
| MeasureCalculationWindowDefinition | Serves as the base class for classes that specify a window definition used to perform calculations within different dashboard items. |
This example emulates the standard Percent of Total window calculation behavior in the calculated field‘s expression.
You cannot include the window functions in a calculated field directly. To support window functions inside a calculated field expression, use the w-Function.