# Switch Transformation

## Switch Transformation

The *Switch* Transformation object matches source data for the criteria specified by the user, and wherever the criteria is 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 in Switch transformation:

1. *Basic Mode*
2. *Enhanced Mode*

The *Basic Mode* in the *Switch* transformation object matches for specific values in the source data and replaces it with the desired output. *Enhanced Mode* enables users to set lookup criteria by writing expressions and thus makes the feature more flexible.

### Video

{% embed url="<https://www.youtube.com/watch?v=pHWbBpfCnn4>" %}

### How to work with Switch transformation (basic mode) in Astera

1. Select your source by dragging the relevant object from the Sources section in the Toolbox on to 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.
{% endhint %}

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FsrLiL0UmuKndpPO8ZU5w%2F1.png?alt=media\&token=bd99bf94-efb4-4f1f-9dc7-9d8019a72d5f)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FJ56cYOGAQp7Rjr93BjaE%2F2.png?alt=media\&token=1c27e2f7-4032-46a3-91ee-dd38e04a3189)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F3Tes7cSZ8lVO8aqZc5Ck%2F3.png?alt=media\&token=adb4e6f8-10a9-4719-9e71-e49ffdba9dc2)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FlmRz3j7XcdvvjMC6HSGN%2F4.png?alt=media\&token=2534635a-a50b-4d0c-8c2e-ad91199d4bd7)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FR9eZuG18YDRlBPM88xiq%2F2e.png?alt=media\&token=ca601ba0-e941-4041-b6e8-206c42bba5b1)

{% hint style="info" %}
**Note:** *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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FkH2CZu7ll4xIgKZ1fedl%2F6.png?alt=media\&token=437f3c5e-61a7-4382-987c-84652ee2fc29)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FwiYG8Bdhdc13lLoCg9zX%2F5.png?alt=media\&token=466ae69d-0d70-45be-adae-d7a28576ef3b)

Astera will look for the values specified in the *Case Value* column in the source file and replace it 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 verification error.
{% endhint %}

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F08y5qsT7qBELhcBbmwaR%2F9.png?alt=media\&token=11eba408-5c8e-4f98-ab77-e203a1ecc0f7)

#### 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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FImD8dBfrAbLX4OYTg7m4%2F7.png?alt=media\&token=e351d626-f1c1-4619-998a-a80b6fd69452)

Data Preview (After Switch)

![](https://docs.astera.com/projects/centerprise/en/10/_images/829.png)

### How to work with Switch transformation (enhanced mode) in Astera

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* and go to the *Switch Map Properties* window and select *Enhanced Mode.*

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FU5Jo1RUqNWZ16fDwctei%2F1e.png?alt=media\&token=cb296e6c-e6bb-4071-9514-b46b7fc2d6c1)

{% 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 about issuing credit cards, which is dependent on 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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FR9eZuG18YDRlBPM88xiq%2F2e.png?alt=media\&token=ca601ba0-e941-4041-b6e8-206c42bba5b1)

Data Preview (Before Switch)

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FImD8dBfrAbLX4OYTg7m4%2F7.png?alt=media\&token=e351d626-f1c1-4619-998a-a80b6fd69452)

Data Preview (After Switch)

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fw8Rlg511JM91eUZKqa8R%2F3e.png?alt=media\&token=c64a8be1-0633-4dd3-959d-1df64e43600e)
