A Guide to Expressions Used in .NET Report Applications
Tags: webdev, dotnet, devops
Published: 2022-08-05 21:09:00

---
canonical_url: https://www.grapecity.com/blogs/guide-to-expressions-used-in-net-report-applications
description: Check out this guide to expressions used in .NET report applications. See more from ActiveReports.NET today.
---

Expressions are an excellent resource for both technical and non-technical users of ActiveReports. For users familiar with Microsoft Visual Basic® .NET or Microsoft Excel functions, many of these functions will be familiar. Whenever designing reports, there may be times when you would like to perform calculations that vary from basic to advanced or change the formatting of the control.

These situations are where expressions shine and can allow for the creation of a more visually appealing report. Expressions allow the user to create a dynamic report using Run-Time calculations that will be made using data from the Data Source.

To start creating an expression, you can select a control such as a textbox, right-click it and select Expression to use the Expression Editor. This will show you a list of available functions and fields.

**NOTE:** When using the Visual Studio or Stand-Alone Designer, the expression must lead with an equal sign ‘**=**'. For the Web Designer, the expression must be surrounded by curly brackets ‘{}’; otherwise, anything in the expression will turn into plain text.

![Syntax at Design Time](https://files.grapecity.com/gc-website-media/wu1nlwbu/01-equal1.png?width=407&height=129)

Syntax at Design Time

![Rendered Result at Run Time](https://files.grapecity.com/gc-website-media/0dbhc4sz/02-equal2.png?width=388&height=117)

Rendered Result at Run Time

### Basic Calculations

The building blocks of an expression will be the basic calculations. These include multiplication (*****), division (**/**), addition (**+**), subtraction (**-**), and concatenation (**&**). The expression will follow PEMDAS logic with any concatenation being done after the calculations are complete.

### Advanced Calculations

Through the Expression Editor, we can also see some more advanced calculations that notably include the following:

*   Pow(number1, number2), which will allow for the use of exponents
*   Sqrt(number) to find the square root of a number
*   Sum(value) to find the total of the field
*   Min(value) and Max(value) to find the smallest and largest values in a field
*   [Other advanced functions](https://www.grapecity.com/activereportsnet/docs/latest/online/common-functions.html)

Below we will cover a few specific functions that can be useful across various industries.

### RunningValue(value, [aggregateFunction](https://www.grapecity.com/activereportsnet/docs/latest/online/common-functions.html))

If you have a value where you would like to find the current total of a field or control from the start of the report to the current page, RunningValue will allow for finding this value. The example below will show the RunningValue of orders from the beginning of the report.

![Page One with No RunningValue](https://files.grapecity.com/gc-website-media/lbxlqxr0/03-runningvalue1.png?width=500&height=40.9967845659164)

Page One with No RunningValue

![Page Two with a RunningValue (Fields!Cost.Value, Sum)](https://files.grapecity.com/gc-website-media/mnalxmsg/04-runningvalue2.png?width=500&height=33.87096774193548)

Page Two with a RunningValue (Fields!Cost.Value, Sum)

Example: =RunningValue(Fields!Cost.Value, Sum)

### Lookup(sourceExpression, destinationExpression, resultExpression, lookupDataset)

The Lookup Function will be familiar to those with experience with SQL Join statements or the VLOOKUP Function in Excel. This function will allow for joining multiple tables to create a more user-friendly report. Our tables will need to have a shared key so that we can link them together.

Our example below will be for a Claims Management System where our Claims and Patient tables have a shared key (**PatientID**) that we will use to link them together. This will allow us to have a table where we can see the patient by name rather than an ID.

![Claims Table](https://files.grapecity.com/gc-website-media/x2hj2mv3/05-lookup1.png?width=500&height=154.36241610738256)

Claims Table

![Patients Table](https://files.grapecity.com/gc-website-media/4u4dt3ic/06-lookup2.png?width=500&height=146.356783919598)

Patients Table

![Lookup Expression in the Expression Editor](https://files.grapecity.com/gc-website-media/ftfizvpx/07-lookup3.png?width=500&height=256.1099796334012)

Lookup Expression in the Expression Editor

![Joined Claims and Patients Tables that allow for a more user-friendly viewing of the tables](https://files.grapecity.com/gc-website-media/xbfphg2e/08-lookup4.png?width=500&height=155.27950310559004)

Joined Claims and Patients Tables that allow for a more user-friendly viewing of the tables

Example: =Lookup(Fields!PatientID.Value, Fields!PatientID.Value, Fields!PatientName.Value, “Patients”)

### Formatting and Style

When designing a report, the expressions are not limited to performing calculations shown in the report. Another use for the Expression Editor is to format and style controls, enabling the user to bring attention to key details in the report. Using expressions, we can change the font (size, color, family, and weight), background color, border (width, color, and style), and text alignment.

Two primary functions will be used when using expressions to change formatting: IIF and Switch. The IIF statement will enable the user to alter the formatting based on if a value is TRUE or FALSE. In contrast, the Switch statement will allow the user to set multiple cases to change the formatting based on the value. Below we have an example of using a Switch statement to change the FontSize, and an IIF Statement to change the BackgroundColor.

![IIF Statement for BackgroundColor](https://files.grapecity.com/gc-website-media/gcebhqf1/09-formatting1.png?width=500&height=15.432098765432098)

IIF Statement for BackgroundColor

![Switch Case for FontSize](https://files.grapecity.com/gc-website-media/uenfaqh0/10-formatting2.png?width=500&height=68.81405563689604)

Switch Case for FontSize

![Report Example](https://files.grapecity.com/gc-website-media/0gljzc0j/11-formatting3.png?width=500&height=40.95563139931741)

Report Example

**Syntax:**

IIF(condition, true, false)

Switch(condition1, value1, condition2, value2,..., conditionN, valueN)

Examples:

=IIF(Fields!AnnualSales.Value >= 80000, "Above Average", "Below Average")

=Switch(Fields!FirstName.Value = "Abraham", "Adria", Fields!FirstName.Value = "Charelotte", "Cherrie")

The following pages in our [documentation](https://www.grapecity.com/activereportsnet/docs/latest/online/expressions.html) will detail the available functions in ActiveReports. If you have any specific questions regarding expressions and functions, feel free to contact our support team and [create a ticket](https://www.grapecity.com/support/contact).