# Calculated Columns (Column Expressions)

A calculated column is identified by an expression. The only condition necessary to make a regular column behave like a calculated column is to set an expression to it.

The following code snippet demonstrates how the standard deviation of the *Consumption* column can be computed for each month in the *Deviation* column.

#### Creating a calculated column

```C#
GridViewDecimalColumn col = new GridViewDecimalColumn();
col.Name = "Calculated Column";
col.HeaderText = "Order value";
radGridView1.Columns.Add(col);
radGridView1.Columns["Calculated Column"].Expression = "UnitsOnOrder * UnitPrice";
```

```VB.NET
Dim col = New GridViewDecimalColumn()
col.Name = "Calculated Column"
col.HeaderText = "Order value"
RadGridView1.Columns.Add(col)
RadGridView1.Columns("Calculated Column").Expression = "UnitsOnOrder * UnitPrice"
```

> caption Figure 1: The last column values are calculated dynamically.

![WinForms RadGridView The last column values are calculated dynamically](https://www.telerik.com/products/winforms/documentation/assets/af1bf56546e7c859f2fdf8a5fdc1bd6b/gridview-columns-calculated-columns-column-expressions001.png)

## Expressions

An expression is evaluated to a value by combining values from multiple cells of the same row and aggregates on the columns using the provided operators.

For decimal columns, you can use simple arithmetic operators like '+' and '\*'. You can also use logical operators like '=' and '<'.

Boolean operators (AND, OR, NOT) are also allowed as well as more complex operators like IN, LIKE, and % (modulus). Operators take the usual precedence. You can alter this precedence using parentheses.

The wildcards % and \* are supported for Text columns, but only at the beginning or the end of a string. Column names are used as keywords and must be *unquoted*. Names (strings) must always be single-quoted.

**Example 1:**

Country = 'USA' Year >= 1999 And LastName LIKE 'A%' Price \* 0.2 + Freight

Dates must be surrounded by the # character.

**Example 2:**

HireDate  #2-1-2002#

The expression parser does not recognize the **Enum** values unless you cast them to an actual value or type.

Decimal values can be used as long as they are represented by a literal matching the current system locale.

The **IIF** function can be used to evaluate a predicate.

**Example 3:**

"IIF(total > 1000, 'expensive', 'dear')

## Custom functions

Expressions can call only built-in functions or methods registered with the active expression context. For the built-in function list and migration details, see [Functions Reference](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/editing/expression-editor/functions-reference) and [Customizing RadExpressionEditor](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/editing/expression-editor/customizing-radexpressioneditor).

## Advanced usage

Refer to the following external resource about further information on the expressions syntax:

<http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression%28VS.80%29.aspx>

## See Also

* [Accessing and Iterating through Columns](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/columns/accessing-and-iterating-through-columns)

* [Converting Data Types](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/columns/converting-data-types)

* [Data Formatting](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/columns/data-formatting)

* [Generating Columns](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/columns/generating-columns)

* [GridViewColumn](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/columns/gridviewcolumn)

* [GridViewDataColumn](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/columns/gridviewdatacolumn)

* [Pinning and Unpinning Columns](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/columns/pinning-and-unpinning-columns)
