# File Lookup Transformation

The *File Lookup* Transformation object in the Astera Data Stack is used to look up values coming from a source. It uses an Excel or delimited file that contains the lookup values as well as the output values to perform the lookup.

File lookup can be performed based on a single lookup field as well as a combination of fields. Similarly, a *File Lookup* Transformation object can return a single output field from a lookup table or a combination of fields. In either case, the output field or fields are returned from the records in which the lookup values match the incoming values.

{% embed url="<https://youtu.be/ekHUtpOGo4k>" %}

## **Use Case**

In this scenario, we have a *Customers* dataset from a fictitious organization stored in a database source. It contains information about customers from different countries.

We want to replace the country names with country codes in our database, by switching them with the lookup values (country codes) stored in an Excel file. To achieve this, we will use the *File Lookup* Transformation object.

## &#x20;**Working with the File Lookup transformation**

1. Select the relevant source object from the *Sources* section in the *Toolbox*. In this example, we will use the *Customers* data stored in a database table.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FoQnZlMZ8uqfeqTuYCD76%2Fimage.png?alt=media&#x26;token=1c90a889-f1d9-4ce9-873b-e4c39050fd46" alt=""><figcaption></figcaption></figure>

Right-click on the source object’s header and select *Preview Output*. You can see the country names in the *Country* field which we want to convert into country codes.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2Fw4PvfAZkUnTqhaFnsSXm%2Fimage.png?alt=media&#x26;token=4bdf02f7-f79f-4b38-8737-2e670ee9e592" alt=""><figcaption></figcaption></figure>

2. Drag and drop the *File Lookup* transformation object from *Toolbox> Transformations> File Lookup* onto the dataflow designer.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FtSN82cto5a4N1MegGsPG%2FFile%20Lookup%20Transformation%20Gif%201.gif?alt=media&#x26;token=fbd1f80c-186a-4ad7-baca-4f50286fc00b" alt=""><figcaption></figcaption></figure>

Now, let’s configure the transformation object.

3. Right-click on the header of the *File Lookup* 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%2Fdpexe8MqoPFvCzhLG1yP%2Fimage.png?alt=media&#x26;token=15086e3f-b002-43f7-b425-194f2faf6ac4" alt=""><figcaption></figcaption></figure>

4. A *File Lookup Map Properties* window will open where you can see an option for *Source File Type*. Here, you need to specify the type of your lookup file.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F3vv35V6I9YCM7LQdmUhF%2Fimage.png?alt=media&#x26;token=dc245954-8e7d-431a-97de-99e443956b46" alt=""><figcaption></figcaption></figure>

You can perform the task using an *Excel* or *Delimited* lookup file.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FnRJawVQDeckJjSuwMLMl%2Fimage.png?alt=media&#x26;token=11cb5c5d-e27c-4711-95d5-23bf976018bd" alt=""><figcaption></figcaption></figure>

5. Select the *Source File Type* from the dropdown menu. In this example, our country codes are stored in an Excel file so we will specify the *Source File Type* as *Excel*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F4oD5VrjUPZkIXTRmRwS8%2Fimage.png?alt=media&#x26;token=04720322-14a4-4e30-8098-7e72cf379ed9" alt=""><figcaption></figcaption></figure>

6. Click *Next* to proceed to the *File Lookup Details* window.

*File Location:* Here, you need to specify the *File Path* to the lookup source file.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FaqHtk5dqtm78KCp9dQ2I%2Fimage.png?alt=media&#x26;token=20b92c93-209a-47b4-9934-5b572cad8530" alt=""><figcaption></figcaption></figure>

You will see two options:

* *First Row Contains Header:* You can check this option if your lookup file contains a header in the first row. Otherwise, you can leave it unchecked.
* *Worksheet:* If your lookup file contains multiple worksheets, you can select the worksheet you want to use to perform the lookup.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FXyMlgp9cXEyswuuVY5VM%2Fimage.png?alt=media&#x26;token=665f8e69-d122-4fbc-a1f8-e7abb9802b7d" alt=""><figcaption></figcaption></figure>

7. Click *Next* to proceed to the *Layout Builder*. Here, you can make changes to the object’s layout by modifying the existing fields or creating new fields.

Once you are done, click *Next*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FevGXdgiV8oMoOu9FO385%2Fimage.png?alt=media&#x26;token=07fe5cf5-6d2c-4a33-acac-4e3f397ef88e" alt=""><figcaption></figcaption></figure>

8. On the next window, you will see various *Lookup Options*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FyfSEgnXKdC3J39ypOpCU%2Fimage.png?alt=media&#x26;token=fc8482c5-3833-4393-a270-8248e7017400" alt=""><figcaption></figcaption></figure>

If multiple values are found, then opt for the *Multiple Matches Found Option.*

* *Multiple Matches Found Option*: This option provides the flexibility to choose the output value if more than one match is found for a single value in your lookup file. The option expands into a drop-down list where you can select one from the following three options:
  * *Return First*: Will return the first matched value found.
  * *Return Last*: Will return the last value among all the matched values.
  * *Return All*: Will return all the values in the lookup file that match a source value.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FCuIVKo7MW2lV5lq6QEhF%2Fimage.png?alt=media&#x26;token=826cf2c1-bc6b-41a2-9510-c029c896280a" alt=""><figcaption></figcaption></figure>

* *If Value Is Not Found In The Lookup List:* In case no lookup value is found against a source value, you can choose one of the following three options to be appended to your output.
  * *No Message:* There will be no message and the output will be the same as the input value.
  * *Add Error:* An error message will appear with the output.
  * *Add Warning:* A warning will appear with the output.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FgC9X8qHuBN6KHBeBdCNG%2Fimage.png?alt=media&#x26;token=93254769-d89c-4368-a1a7-b7113abc9190" alt=""><figcaption></figcaption></figure>

* *If Value Is Not Found In The Lookup List, Assign Value:* If no lookup value is found against a source value, you can assign an output value of your choice.
  * *Assign Source Value:* Will return the source value in the output.
  * *Assign Null:* Will assign null to your output value.
  * *This Value:* You can select this option and assign any value of your choice.

9. Click *Next*. This will take you to the *Config Parameters* window, where you can further configure and define parameters for the *File Lookup* transformation object.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FXwq6mibLWgCCbL5uXy2D%2Fimage.png?alt=media&#x26;token=18b3f875-97da-4407-9479-87c6ed826712" alt=""><figcaption></figcaption></figure>

Once you have configured the *File Lookup* transformation object, click *OK*.

10. Map the *Country* field from the *Source* object to the *Country* field in the *File Lookup* transformation object. Now map the *Code* field from the transformation object to the *Country* field in the *Database Table Destination* object.

This is what your dataflow will look like:

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2Fs1xEXivhw6ncGs90jwOI%2Fimage.png?alt=media&#x26;token=3135a73d-c5b7-4afd-803c-99d83523e87a" alt=""><figcaption></figcaption></figure>

11. Map the remaining fields from the source object to the destination object.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F1BwDElu5rnNngrvHDdes%2Fimage.png?alt=media&#x26;token=5285f4fe-db02-4b17-9710-3e772780cb4d" alt=""><figcaption></figcaption></figure>

12. Right-click on the destination object’s header and select *Preview Output*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FhMSkavoi5w6Oa4uajRGn%2Fimage.png?alt=media&#x26;token=4931775b-0510-4597-9931-0c2dbd3fee37" alt=""><figcaption></figcaption></figure>

13. You can see that the country names in the database table have been successfully converted into country codes.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FwDjUPhp5a3MgUxMKZx6p%2Fimage.png?alt=media&#x26;token=65fcffb3-64a2-494e-8d97-244ede2d9b46" alt=""><figcaption></figcaption></figure>

This concludes using the *File Lookup* Transformation object in Astera Data Stack.
