An expression can be used to set the value of a control in the report or to define a condition to set specific styles. You can set expressions through the Expression Editor dialog while setting values in the properties window.
The editor allows you to choose from a number of fields available to the report as well as to a particular property. You can access the Expression Editor by selecting nearly any property of a control and choosing f Expression from the drop-down list. All expressions are enclosed within curly braces '{}'. Even the expression for a field value for a TextBox is set as follows: {LastName}.
While building an expression, you can directly add the entire expression or part of it in the Expression pane of the Expression Editor. Then use the Insert or Append buttons to create a complete expression.
You can concatenate fields with strings and with other fields. For e.g., use the following expression to get a result like "Customer Name: Bossert, Lewis":
Customer Name: {LastName} , {FirstName}
You can use expressions in properties like Color, Font, Border, etc. on specific field values based on a condition, to highlight a part of data. The formula for conditional formatting is:
{IIF(<Condition>, <TruePart>, <FalsePart>)}
For e.g., if you enter the following expression in the Font > FontWeight property of a text box that displays names of people, you get the name "Denise" in bold.
{IIF(FirstName = "Denise", "Bold", "Normal")}
Similarly, if you enter the following expression in the Background >Color property of a text box in a table, then you get alternating 'Transparent' and 'LightGray' colored text boxes in the rows of the table.
{IIF(RowNumber(Nothing) mod 2, "Transparent", "LightGray")}
You can use a number of aggregate and other functions in your expressions. ActiveReports includes a range of functions, including running value, population standard variance, standard deviation, count, minimum and maximum. For e.g., use the following expression to get a count of employees.
{Count(EmployeeID, Nothing)}
You can set the following calculations for Summary and Total Value Calculations.
Calculation Option | Result |
---|---|
Default | current value |
% Grand Total | current value ÷ grand total of the tablix |
% Row Group Total | current value ÷ current row group grand total |
% Parent Row Group Total | current value ÷ parent row group subtotal in the current column group For subtotals, subtotal ÷ grand total of the current column group |
% Column Group Total | current value ÷ current column group grand total |
% Parent Column Group Total |
current value ÷ parent column group subtotal in the current row group |
It is now possible to set the common expression for multiple TextBoxes (including TextBoxes in Table and Tablix) for all the properties.
To set the common expression for multiple TextBoxes (having the same or different data fields), first select the TextBoxes. In the Properties Window, select the property for which you want to set the expression, and then select Expression to open the Expression Editor. Under the Values, expand the Common Values node, select Current Textbox Value, enter a valid expression with the ($$$) variable, and click Save.
Let us see how this works by looking at two samples, applied to the 'Page/Invoice.rdlx' report. This report is available in the 'resources' folder of WebDesigner_MVC_Core sample.
Example 1: Add the Sum expression to multiple data fields in a Table data region.
Steps:
$$copyCode$$
|
|
---|---|
{Sum($$$)} |
{Sum(Quantity)}
{Sum(UnitPrice)}
Example 2: Add a background color to multiple data fields in a Table data region.
Steps:
$$copyCode$$
|
|
---|---|
{iif($$$ > 14, "Green")}
|
{iif(UnitPrice > 14, "Green")}
{iif(UnitPrice - UnitPrice * Discount > 14, "Green")}
This expression evaluates the background color to Green color if the selected values are greater than '14'.