# Filter Transformation

## **Overview**

The *Filter* transformation object in Astera Data Stack is used to filter out records based on some pre-defined rule. The records that match the specified rule are filtered out and can be mapped further in the dataflow whereas the records that do not satisfy the specified condition are omitted.

The rule or logic to filter out records from data can either be chosen from an extensive library of built-in functions or you can write one of your own.

*Filter* transformation is quite similar to *Data Quality Rules* in its functionality. However, unlike *Data Quality Rules*, which return an error or warning when the rule condition fails while still passing the record downstream, the *Filter* transformation will completely filter out any such records. T

he filtered records, as well as their status, will not be accessible to any downstream object on the dataflow, including any type of log.

## **Use Case**

In this case, we have *Customers* data for a fictitious organization stored in a *Delimited file* source. We want to filter out the records in which:

* *Country* = Germany
* *Contact title* = Owner

To filter out these records from our source data, we will use the *Filter* transformation object and write the relevant expression in the *Expression Builder* to achieve our desired output. We will then write our filtered output to a *Fixed length* destination.

## **Using the Filter transformation**

1. Retrieve your source data by using the relevant source object from the Sources section in the Toolbox. In this case, our sample *Customers* data is stored in a delimited file so we will be using a [*Delimited File Source*](https://documentation.astera.com/v/astera-data-stack-v8/dataflows/sources/delimited-file-source) object to retrieve this data in the dataflow.
2. Next, drag and drop the *Filter* transformation object from the Transformations section of the *Toolbox* to the designer and map fields from the source object to the *Filter* transformation object.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FOeLuAzFzfEmjvdHn2QFx%2FFilter%20Transformation%20Gif%201.gif?alt=media&#x26;token=3ec6b458-5922-4c51-8e7e-acbc64e9762f" alt=""><figcaption></figcaption></figure>

3. Right-click on the *Filter* transformation object and select *Properties*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FD655e4ncmo8quPtk4onm%2Fimage.png?alt=media&#x26;token=527da702-b77f-432d-89fa-7f371256a835" alt=""><figcaption></figcaption></figure>

A *Layout builder* window will now open. Here you can modify fields and the object layout.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FSFTODbW2T8HETXACX74q%2Fimage.png?alt=media&#x26;token=884a2e98-ab27-46a5-8428-7a2f3d38fa33" alt=""><figcaption></figcaption></figure>

4. Click *Next*. This will take you to the *Filter Transformation Properties* window. Here, you can see the following three sections:

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FCoCuQQlfEtNyi0hvq8qc%2Fimage.png?alt=media&#x26;token=56010f6e-e69d-4ee6-a0c9-e75ff6e500a6" alt=""><figcaption></figcaption></figure>

* *Functions*: An extensive library of built-in functions organized in various categories. From here, you can select functions according to your requirements.
* *Expression:* The filter expression will appear in this *Expression* box. You can either write your own expression or choose from the built-in functions library.
* *Objects*: Contains the object layout. You can double-click on any element in the layout to write it in the *Expression* field.

In this example, we want to filter out records of customers with the *ContactTitle*, ‘Owner’, and *Country*, ‘Germany’. For this, we will write the following expression in the Expression box:

Country = “Germany” and ContactTitle = “Owner”

After writing the expression, click on the *Compile* button to check if the expression is correct. If the *Compile Status* is *Successful*, the expression is correct. If not, then you need to check and rectify your expression before proceeding to the next window.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FrB1Q2WKb5wHRMcOqrvSx%2Fimage.png?alt=media&#x26;token=f41f8bc6-2b87-4b34-af06-89f1fc4f5c41" alt=""><figcaption></figcaption></figure>

6. Click *Next*. This will take you to the *Config Parameters* window where you can further configure and define parameters for the *Filter* transformation object.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FJwqen9kJCAdBT1ruRFfs%2Fimage.png?alt=media&#x26;token=9ec95342-4045-4490-aaa0-edac8c117831" alt=""><figcaption></figcaption></figure>

7. Click *Next* to proceed to the *General* *Options* window. This window consists of options common to most objects in a dataflow, such as:

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FKISX8P7i9LdTXA9ofMDW%2Fimage.png?alt=media&#x26;token=2f3a4af3-39e7-4ce6-91e5-8e9df811afd8" alt=""><figcaption></figcaption></figure>

* *General Options* Window: This window shares options common to most objects in the dataflow.
  * *Clear Incoming Record Messages:* When this option is checked, any messages coming in from objects preceding the current object will be cleared. This is useful when you need to capture record messages in the log generated by the current object and filter out any record messages generated earlier in the dataflow.
  * *Do Not Process Records with Errors:* When this option is checked, records with errors will not be output by the object. When this option is off, records with errors will be output by the object, and a record message will be attached to the record. This record message can then be fed into downstream objects in the dataflow, for example, a destination file that will capture record messages or a log that will capture messages and collect statistics as well.
  * The *Comments* input allows you to enter comments associated with this object.

The *Filter* transformation object has been configured. Click *OK*.

8. To preview filtered records, right-click on the *Filter* transformation object and select *Preview Output*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FxeRhXZIs3w0ZtnsAyXoP%2FFilter%20Transformation%20Gif%202.gif?alt=media&#x26;token=fd01bb7a-7f6e-4e79-9469-9b5c587e0da0" alt=""><figcaption></figcaption></figure>

The output would look like this:

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FHAOu4GxOIYpzufdm3CbM%2Fimage.png?alt=media&#x26;token=89bb5550-bb8d-421a-9b01-dfa4647048c0" alt=""><figcaption></figcaption></figure>

9. You can now write your output to a destination or further transform it by applying some transformation.

In this case, we will write our output to a [*Fixed Length File* *Destination*](https://documentation.astera.com/v/astera-data-stack-v8/dataflows/destinations/fixed-length-file-destination).

Rename your destination object by double-clicking its header. Here, we will rename it as *German\_Customers*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FuY3Dmj9Sbq8NyIAS7DEx%2Fimage.png?alt=media&#x26;token=e45c6e21-275a-4a82-8b74-a17224a2b672" alt=""><figcaption></figcaption></figure>

This concludes using the *Filter* transformation object in Astera Data Stack.
