How to: Pass a Dashboard Parameter to a Calculated Field's Expression
- 3 minutes to read
This tutorial demonstrates how to pass a dashboard parameter to a calculated field’s expression using the WinForms Dashboard Designer.
The DevExpress dashboard is already connected to the SalesPerson view of the Northwind database. The Grid dashboard item is bound to the CategoryName and Discount fields.
Suppose that you want to create a calculated field that returns different values depending on the selected parameter value. In the example, the calculated field will return TRUE or FALSE depending on whether the average discount exceeds the selected parameter value. To do this, perform the following steps.
- Create a dashboard parameter that returns a list of predefined discount values.
- Pass the created parameter to the expression of the calculated field.
Create a Parameter
To create a dashboard parameter, click the Parameters button in the Home ribbon tab.
In the invoked dialog, click Add to create a new parameter…
…and specify its settings in the following way.
- Specify the Description that will be displayed in the Dashboard Parameters dialog for this parameter.
Set Look-Up Settings to Static List and click the ellipsis button next to Values. In the invoked Parameter Values dialog, specify possible parameter values (0.01, 0.05 and 0.10)…
…and click OK.
- Change the parameter’s Type to Number (double-precision floating-point). Then, specify the default parameter Value as 0.05.
- Finally, change the parameter Name to discountValue.
Click OK to create the dashboard parameter.
Pass the Parameter to a Calculated Field’s Expression
To pass the created parameter to a calculated field’s expression, create a new calculated field by clicking the Add Calculated Field button in the Data Source ribbon tab.
In the invoked Expression Editor, specify the following expression: Iif(Avg([Discount]) >= [discountValue], ‘TRUE’, ‘FALSE’)
Note
Note that this expression contains the following objects.
- The Iif logical function returns either TruePart or FalsePart, depending on the evaluation of the Boolean Expression. You can find this function in Functions.
- The Avg aggregate function returns the average of all the values in the expression. You can find this function in Aggregate Functions.
- The Discount data source field can be found in Fields.
- Finally, the discountValue parameter can be found in Parameters.
Click OK to create a calculated field. Then, right-click the created field, select Rename and change the name of this field to IsGreater.
Drag and drop the IsGreater field to the Columns section of the Grid dashboard item and see the result.
You can see that the column corresponding to the IsGreated field returns TRUE or FALSE depending on whether the discount value is greater than 0.05 (or 5%). You can click the Parameters button placed within the dashboard title to change the current parameter value in the Dashboard Parameters dialog.
In this case, values returned by the IsGreater field will be recalculated.