# Filter data cube using complex logical expression

Contents[Hide]

## 1. Overview

This article shows you how to filter the data cube with complex logical expressions.

In cases of logical expressions that use a combination of AND and OR operators, the Filter transform is not adequate to filter the data needed.

In this case, we need to use the combination of the Calculated Element transform and the Filter transform

## 2. Editing expression in Calculated Element transform

Once the table has been placed in the Data Cube Designer, place the Calculated Element transform.

Configure the transform, and click the Add icon under Calculated elements.

Name the calculated element, and set the data type of the element to Boolean. Next, click on the "Edit expression on editor". This will open the Script Editor.

In the Script Editor pane, place the conditions that you need to want to filter out in the data cube. Make sure that it meets the criteria you want to accomplish, and return "true".

For example, we want to return values that have the following condition: (COL_A > 5 AND COL_B > 5000) OR (COL_A = 1 AND COL_C > 0.01)

In this case, we will use a script shown below:

```if ((\$TerritoryID\$ > 5 && \$SalesYTD\$ > 5000) || (\$TerritoryID\$ == 1 && \$CommissionPct\$ > 0.01)){
return true;
}
```

For the list of columns that you could use to create the expression, you could check on the Placeholders section in the Calculated Element screen.

Click "Save", and it will refresh the data cube to show the results. It will have another column in the data cube to display the results of the transform.

## 3. Placing the Filter

After placing the Calculated Element transform, add the Filter transform, and configure it.

In Filter, click on Edit item next to the created Calculated Element.

Select the Element Operator "Equals", and place a checkmark under Boolean Value.

Click OK, and click on Process Results. In the Data Preview, you will see the filtered results.

On the Data Output Elements, click 'X' on the column with the Calculated Element. This will hide the boolean transform.