Edit Expression Overview

Important

This content is archived and is not being updated. For the latest documentation, see Microsoft Dynamics 365 product documentation. For the latest release plans, see Dynamics 365 and Microsoft Power Platform release plans.

Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

You use expressions throughout a report definition to control content and format the data in a report. You can use the Edit Expression window to write and edit expressions for an auto design report in Model Editor. Expressions are written using Visual Basic.

When you define a precision design report in SQL Report Designer, you can use the Expression dialog box for Report Designer to write and edit expressions. The Edit Expression window is an extension of the Expression dialog box. This topic describes the Edit Expression window. For information about the Expression dialog box, see Expression dialog box.

You can also change the expression text in the Property window. Use the Property window when you know the expression to type. Use the Edit Expression window when you need to build an expression by adding items from a list.

The Edit Expression window includes a code editor and a list of items that you can use in an expression. The code editor supports IntelliSense, statement completions, and syntax coloring so that you can easily detect syntax errors. The Edit Expression window is context-sensitive, so category items change depending on the report item that you are working with. For example, when you select the Datasets item, the list of datasets available for the report displays in the Edit Expression window. The Edit Expression window includes additional categories of items specific to Microsoft Dynamics AX reports. You can access the Labels category and the Methods category in the Edit Expression window but they are not available in the Expression dialog box as options. To add Labels or Methods to expressions in a precision design report, you must type the expression in the code editor of the Expression dialog box.

The following illustration is a screenshot of the Edit Expression window in Model Editor.

Expression Editor

There are a couple ways to invoke the Edit Expression window window in Model Editor. Many of the properties in the Properties window for report elements include <Expression…> or as an option in the drop-down menu. When you click <Expression…> or , the Edit Expression window displays.

To invoke the Expression dialog box in a precision design report, right-click a report element, and then click Expression.

Code Editor

When you open the Edit Expression window, the code editor displays the current expression for the element. If no expression exists, it will display an equal sign (=). When creating or editing an expression, you can select items from the various categories. Just select a category, select the item that you want to add to the expression, and then click Paste. You can also double-click an item to add it to an expression.

A wavy red underline indicates a syntax error. Hover over the underlined text to see the error message. When you have items followed by a punctuation separator, you will see a drop-down list of available properties, members, or methods. From the drop-down list, you can type the first few characters followed by a tab to automatically complete the selection.

Categories

The following table describes the categories of items that can be used in an expression.

Category

Description

Constants

Displays a list of predefined values valid for the report element that are based on constants.

For example, a property based on color shows valid color names. For a property that is a Boolean data type, values are True and False.

Globals

Displays a list of items in the global collection that can be used in an expression, such as ReportName and UserID.

Parameters

Displays a list of the report parameters that are defined in the report that can be used in an expression.

For example, if the report contained a report parameter for Region, you would see the Region parameter listed when you select the Parameters category. You could then set the Expression property for the Group on folder to group data based on the region parameter that was selected like =Parameters!Region.Value.

Fields

Displays a list of fields that can be used in an expression. The list varies depending on the element that you are working with.

Datasets

Displays a list of datasets available for the report and lists the fields for each dataset.

Labels

Displays a list of labels that are available for the report. This category is only available in the Model Editor version of the Edit Expression window.

Methods

Displays a list of data methods and built-in methods that are available for the report. This category is only available in the Model Editor version of the Edit Expression window.

Operators

Displays the operators that you can include in a calculation or string manipulation.

Common Functions

Displays a list of functions that are commonly used in expressions.

Expressions

Expressions can be simple or complex. A Simple expression contains a reference to a single dataset field, label, or parameter. For example, the expression for a dataset field appears as =Fields!Name.Value. Simple expressions are created for you when you drag a field from a dataset onto a report design. You can also type them directly into the Property window for an Expression property or a property that has <Expression…> or (…) in the drop-down options. A Complex expression contains references to items such as datasets, fields, parameters, labels, data methods, and operands.

Examples of Expressions

An expression begins with an equal sign (=). This section contains references to report examples. The following table describes some scenarios and examples of expression:

Scenario

Description

Property value example

Use an expression for a data element in a report design.

You can set the following properties for data to an expression:

  • Caption property to set the caption of the data item

  • Expression property to set the value of the data item to a value

  • Point Label property to set the label that should be used to display the point label values

The following list provides an example of each of these properties set to an expression:

  • Caption =Labels!@SYS181459

  • Expression to a simple expression like =Fields!SalesPerson.Value or a complex expression like =Sum(CDbl(Fields!Actual.Value))

  • Point Label =Sum(CDbl(Fields!Actual.Value))

Use an expression for a report parameter

You can set the following properties for a report parameter to an expression:

  • Use the Values property to set the Value Label pair for a non-queried value.

  • Use the Default Value property to set a default value for the parameter

The following list provides an example of each of these properties set to an expression:

  • Set the Value property to 1 and set the Label property to =Today() then set a second Value property to 2 and set the Label property to =System.DateTime.today().addYears(-1)

  • If the parameter is a DateTime data type, then you could set the Default Value property to =Today()

For additional examples of expressions, see Expression Examples in Reporting Services.

See also

Working with Expressions

How to: Add a URL Drill Through Action on a Report