# Switch Transformation

The *Switch* Transformation object matches source data for the criteria specified by the user, and wherever the criteria are met, it replaces the information in the particular field with the desired output (also specified in the layout). This gives users more control over their data and helps them manage it in a better way.

There are two modes of Switch transformation:

1. *Basic Mode:* matches specific values in the source data and replaces them with the desired output.
2. *Enhanced Mode:* enables users to set lookup criteria by writing expressions and thus makes the feature more flexible.

### Working with the Switch transformation (Basic Mode)

{% embed url="<https://youtu.be/pHWbBpfCnn4?list=PLmyM3TZtVUyJfz1bkpZ-CxJ33fAwHIbug>" %}

1. Select your source by dragging the relevant object from the Sources section in the Toolbox onto the dataflow designer and configure the connection by putting in relevant details.

{% hint style="info" %}
**Note**: In this example, we are working with an *Excel Workbook Source* that contains employee information for a fictitious organization, but you can select the source type from a wide range of options provided in Astera Data Stack.
{% endhint %}

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FIzkI3i9kEoYA5q2OZksq%2F1.avif?alt=media\&token=a272316c-63cf-4e89-bb11-f497459f772b)

2. After setting up the connection and configuring the source file, drag the *Switch* transformation object from the *Toolbox*. If the *Toolbox* is hidden, go to *View > Toolbox > Transformation > Switch.*

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FsUB5Wc1lqKHY3Od4M38n%2F2.png?alt=media\&token=4219269d-0805-4638-b763-f227bb51492b)

3. Map the required fields from the source to the *Switch* transformation object.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FFf1xnnEzMsihM5jBKgUo%2F3.png?alt=media\&token=7cea8d26-2b25-430f-90cd-b45c6c98cab1)

4. Either double-click on the *Switch* Transformation object to open the *Properties* window or right-click on the object and go to *Properties* from the list.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FDnhKqzRcducaiHIvOUeV%2F4.avif?alt=media\&token=aa7ca3f0-e7fd-4e48-afb3-c1c5108c7ca1)

5. The first window is the *Layout Builder* window. Here you can manage the fields (add and/or remove the fields) to make your Switch field layout.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2Fc3nhZLgWLk8jxQCCOHat%2F5.avif?alt=media\&token=266d45b7-c530-4989-ae36-31450352ef49)

{% hint style="info" %}
**Note:** The *Switch* transformation only allows one output field. If you check the output box next to multiple fields, Astera will show a verification error.
{% endhint %}

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FMz5l729MmtcGXUst3zzL%2F6.png?alt=media\&token=6cc9d35c-62cc-40ea-a807-ab0d3241ed17)

6. After specifying the layout and selecting the relevant output field, click *Next*. This will take you to the *Switch Map Properties* window. At this stage, you can select the mode of the *Switch* transformation and assign the rules in the *Case Value* and *Output Value* sections.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2Fk8nJWAT6DLXp90anM0y0%2F7.png?alt=media\&token=2a8f9d44-3965-483e-b6bf-fac4456f2885)

Astera will look for the values specified in the *Case Value* column in the source file and replace them with the corresponding values in the *Output Value* column.

{% hint style="info" %}
**Note:** *Switch* transformation only allows one default value and if you select multiple default values, Astera will give a verification error.
{% endhint %}

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FC9l1dJvIXfgUl6NH5yYD%2F8.avif?alt=media\&token=6717d556-1cd3-494f-b46c-8e2c6e01fe98)

#### Example

In this example, the source table contains information about departments in numbers. We will use the *Switch* transformation object in basic mode, to switch the stored numeric information with the descriptive information.

Data Preview (Before Switch)

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F0ITFGqt172wvQh29hmbn%2F9.avif?alt=media\&token=351da94d-d4e5-4122-8c18-f15bf4ee8a74)

Data Preview (After Switch)

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FG2sIOcGsBjQ16I8b5cdc%2F10.avif?alt=media\&token=cc2cc0aa-ca17-4a94-b16f-01ecd47d9c67)

### Working with the Switch transformation (Enhanced Mode)

Steps 1-5 are going to remain the same even when working with the *Enhanced Mode* in Astera.

1. After you have created the layout in the *Layout Builder* window in the object’s properties, click *Next* go to the *Switch Map Properties* window and select *Enhanced Mode.*

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FmPMp8LhIo6Sc5MlLA7Kn%2F11.png?alt=media\&token=6f35b361-b326-41fe-b9e1-1591f1f49c7e)

{% hint style="info" %}
**Note:** Switch transformation is not field-specific in the enhanced mode therefore, the option for selecting the *Switch Field* is disabled.
{% endhint %}

#### Example:

An organization stores information about employees’ salaries. They have set criteria for issuing credit cards, which are dependent on an individual’s salary. In this scenario, to see which individual is eligible for which perk, define the salary range in the *Case Expression* field and specify the corresponding output in the *Output Expression* section (See the screenshot above).

To store the information in a separate field, we created a new field (*CreditCard*) in the *Layout Builder* and selected it as the *Output*.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FfYA6jsUlOmFF7lh5cQca%2F12.png?alt=media\&token=f1c4914d-8cf7-49bb-a5ce-96d26eb0a671)

Data Preview (Before Switch)

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F6Ge3OnebUpY6x762INES%2F13.png?alt=media\&token=c848756a-0cfe-4129-9b18-566623f80f99)

Data Preview (After Switch)

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2Fq3wPU5QagCaqdWCmChxx%2F14.png?alt=media\&token=9dc696f6-632c-44d4-9dec-389e54c90b49)
