# Variables

The *Variable* object in Dataprep allows you to parameterize values such as file paths, dataset names, or filter conditions, that can be reused throughout your recipe without reconfiguration. By using variables, you can make your recipes dynamic, flexible, and easier to manage when integrated into dataflows or workflows.

### Example Use Case

Imagine you receive monthly sales files that all need the same cleansing and transformation. Without variables, you’d have to create a separate recipe for each file, which is time-consuming and hard to maintain.

This is where variables help. Instead of hardcoding the file path in your recipe, you can define a variable and use it as the input source. When the recipe is run in a dataflow, the variable can be mapped to different files or even an entire directory.

### Creating a Variable

1. Open your recipe in Dataprep.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FCX75hjYT65vflatwRugy%2Fimage.png?alt=media&#x26;token=6ea82778-c3de-470b-a74c-3d26e2fcc063" alt=""><figcaption></figcaption></figure>

2. Navigate to *Define > Variable* in the toolbar.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2Fu5wWlDdm2m7YpEF7Uyoy%2Fimage.png?alt=media&#x26;token=70a14982-ba2a-4a56-90e9-fcd207712c16" alt="" width="563"><figcaption></figcaption></figure>

3. In the *Recipe Configuration – Variable* window:

* **Name**: Give the variable a descriptive name.
* **Type**: Choose a data type (e.g., *String, Integer, Boolean*).
* **Value**: Enter the value of this variable. For this use case, we can paste the file path of one of the sources here.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FzSb876lylpcJkSpQOxNr%2Fimage.png?alt=media&#x26;token=e3d3309f-2251-4557-a4b2-efeaa55e7121" alt="" width="388"><figcaption></figcaption></figure>

{% hint style="info" %}
**Note:** For file paths, prefix the value with @
{% endhint %}

4. Click <img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FXcflgpTceQCIYfjrsOQ4%2Fimage.png?alt=media&#x26;token=994aa279-35b8-4f33-9f44-73e7bf86c488" alt="" data-size="line"> *Apply* to save the variable.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FVREybftooz0sox5wMjQL%2Fimage.png?alt=media&#x26;token=8b94fffa-9490-43f0-b04d-e3cc4fd7d0a8" alt=""><figcaption></figcaption></figure>

### Using Variables in Recipes

1. Add a *File Source* object.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FCshjYMjI3yhuk0yFKPx5%2Fimage.png?alt=media&#x26;token=5882e328-1a29-435e-bd65-c8a9f14ba591" alt="" width="563"><figcaption></figcaption></figure>

2. Set *File Location* to *Path from Variable*.
3. Select the variable you defined.
4. Provide a dataset name and click *Apply.*

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FUx7XUbSY7WIV1g4j2aOf%2Fimage.png?alt=media&#x26;token=79522252-bf8d-465a-aa91-3ca86d68cec1" alt="" width="369"><figcaption></figcaption></figure>

5. Perform the required cleansing and transformation steps on this dataset. This recipe will later be reused for other files through the variable.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FF1kg2X7QvndupeqxsY8h%2Fimage.png?alt=media&#x26;token=97e0f46e-3e13-4395-9f9d-0169f1b54e21" alt=""><figcaption></figcaption></figure>

### Using Variables in Dataflows

Once the Dataprep recipe has been configured, create a dataflow to process all datasets using this recipe. To do this:

1. Add a *Dataflow* to your project.
2. Drag-and-drop a *Dataprep Source* object onto the designer, right-click on the header and select *Properties* from the context menu.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FXRRcf5ixutx4OX7WGzBc%2Fimage.png?alt=media&#x26;token=ee442449-2b5b-4163-9221-fd33bc0847da" alt=""><figcaption></figcaption></figure>

3. Provide the file path to the Dataprep recipe and click *OK*.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2F8Eu6b24JYnjDI2wgf6SG%2Fimage.png?alt=media&#x26;token=3a60d5d6-9021-4ebf-8dc2-dedde1e0465a" alt="" width="563"><figcaption></figcaption></figure>

4. Right-click on the Dataprep source object and select *Transformation*. This will allow you to map any inputs to the source object.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FjIvrbnqt6hkEG33r6F1Y%2Fimage.png?alt=media&#x26;token=a0e96a69-bdb6-4a0b-a63c-b796c2e97ee2" alt="" width="352"><figcaption></figcaption></figure>

5. Drag-and-drop a *File System* *Items* source object from the toolbox onto the designer and configure it to the directory where the datasets are stored.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FSOHWgxAI5QZoenqKubor%2Fimage.png?alt=media&#x26;token=1f778fff-9778-4319-a861-910ea55680c1" alt="" width="563"><figcaption></figcaption></figure>

6. Map the *Full Path* to the *File Path* in the Dataprep Source object’s input node.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FkeWTfgDQcmeUrwQ8eQfj%2Fimage.png?alt=media&#x26;token=ccfb37fb-8b99-40f8-9488-3c47605743b2" alt="" width="559"><figcaption></figcaption></figure>

7. Your Dataprep Source has now been configured successfully, and you can now write the output to a destination.

<figure><img src="https://3181888596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzEifS4h8yurLAAwiGNX2%2Fuploads%2FGb8eu9v4lkT9odkT3Kqm%2Fimage.png?alt=media&#x26;token=e1434ab0-e42c-4786-8888-815a326919f6" alt="" width="563"><figcaption></figcaption></figure>

Now, your dataflow dynamically processes all datasets in the folder using the same recipe.
