ActiveReports 18 .NET Edition
Report Authors: Designer Components / WebDesigner / Expressions
In This Topic
    Expressions
    In This Topic

    You can use an expression to set the value of a control in the report or set conditions under which certain styles apply. 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.
     

    Expression Editor Dialog

    Concatenating Fields and Strings

    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}

    Conditional Formatting

    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")}

    Functions

    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)}

    Summary and Total Value Calculations

    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
    For subtotals,
    subtotal ÷ grand total of the current row group

    Multiple TextBoxes Operations

    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:

    1. From the WebDesigner_MVCcore sample, open the 'Page/Invoice.rdlx' report.
    2. Select the {Quantity} and {UnitPrice} fields in the Details row of the Table data region.
    3. Go to Common > Value property and enter the following expression in the Expression Editor:
      $$copyCode$$
      {Sum($$$)}
      
    4. Save the expression and close the Expression Editor.
    5. Check that the 'Value' expression is updated for each of the selected fields to the following values:
         
      • {Sum(Quantity)}
      • {Sum(UnitPrice)}

    ($$$) variable with Sum expession



    Example 2: Add a background color to multiple data fields in a Table data region.

    Steps:

    1. From the WebDesigner_MVCcore sample, open 'Page/Invoice.rdlx' report.
    2. Select the {UnitPrice} and {UnitPrice - UnitPrice * Discount} fields in the Details row of the Table data region.
    3. Go to Background > Color property and enter the following expression in the Expression Editor:
      $$copyCode$$
      {iif($$$ > 14, "Green")}
      
    4. Save the expression and close the Expression Editor.
    5. Check that the 'Background Color' expression is updated for both selected fields to the following values:
         
      • {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'.

    Using ($$$) variable for the background color