# Variables

A variable is a data value that can be a static or a dynamic value based on your requirement.

Here we have two types of Variables in Report based on the scope of their usage:&#x20;

* **Local Variables**: These variables can be used only within the scope of the Report in which they are created.
* **Global Variables**: These variables can be used in any report.

### **How to create/add Local variables in Report :**

* First, you need to go to the **Custom** Tab alongside the Column tab.&#x20;
* Now go to the **Variable** Section and click on it.&#x20;
* A dropdown will open up.&#x20;
* You now need to select the Variable type **Local** and click on **Add Variable** button.&#x20;
* Now **Add Variable** window will open. It has the following components:
  1. **Variable Name**: This allows you to name the Variable you want to add.&#x20;
  2. **Label**: This allows you to add a Label to your Variable.
  3. **Data Type**: This allows you to choose the Data type of the Variable's value. It can be Text, Date, and Numeric.
  4. **Input Method**: This allows you to choose the input method for Variable entries such as Type In,  Multiselect Pickup List, Pickup List, or both combined.
  5. **Suggest Value From:** If the data type is text and  input method is any-other than Type In, then this field will be shown. It has two option Manual or Column.&#x20;
     1. **Manual:** When selected, variable values must be **manually added or entered** at the time of variable creation.
     2. **Column:** When selected, users can **choose values directly from existing columns** in the dataset.
  6. **Default Value**: Here you need to specify the default values for the Variable as per your need.&#x20;

     For Type In variables- You need to specify a single Default value.

     For Pickup List variables- You need to give multiple comma-separated values as default values. Then you can choose the desired **Variable** value from the Pickup list.

     **Special Case: Date Data Type**

     If the **Data Type** of the variable is set to **Date**, you'll be given two options for how to define its default value:

     **1. Manual**

     * Allows you to **manually enter a specific date** during variable creation.
       * Best when the default value is fixed or rarely changes.

     **2. Custom Relative Date**

     * Lets you choose a **dynamic, relative date** based on the current date.
     * Ideal for variables that should adapt over time.

     **Available Options:**

     * **Today**
     * **Tomorrow**
     * **Yesterday**
     * **Start of current week** (Starts Sunday)
     * **End of current week** (Ends Saturday)
     * **Start of current month**
     * **End of current month**
     * **Start of current year**
     * **End of current year**

7. Now click on **Add** button and your Local variable will be added.

**Note\*\*:** Global variables can only be created in Admin >> Settings>> Global Variable.

### **Where to Use Variable in Report :**

You can use the Variable in the following features:

**Custom Columns:** You can use variables to create a new Custom Column.&#x20;

For eg: Let's say you have Employees data and you want to create a new column **"Employee Status"** having two values **"New**" and **"Old**" calculated based on the fact whether the Joining date for an employee is after a certain(**2023-01-01**)date or not. To achieve this you can use a Variable with Date data type with the defined default date value as '**2023-01-01'** which you want to use for the comparison between **New** and **Old** employee. You then need to use this defined Variable in the **"Case When"** SQL query to create the **Custom Column** **"Employee Status"** and then you can change this Variable Date value according to your need to separate employees into New or Old.

**Custom Metrics**: You can use variables to create new Custome Metrics.&#x20;

For Eg: If you have Banking Loan data and you want to create a new Metric **"Total Payout"** calculating the total loan amount to be paid over a tenure based on different sets of Interest rates **10%, 15%, 20%**, etc. Here you can use a Variable with a Numeric data type named **"Interest Rate"** with some default value like 10 and use this for the **Custom Metric** creation. So now you can later change the variable value to some different interest rate based on which new **"Total Payout"** will be calculated.

**Custom Filters**: You can use variables to create new Custom Filters as well.

### **Note\*\*:**&#x20;

* To identify the variable in an expression, use {{variableName}} and enclose it within curly brackets.&#x20;
* To identify the global variable in an expression, use {{Globals.variableName}} and enclose it within curly brackets.

Once the **Variable** has been created and used in some **Custom** calculations then you can directly change it in the Reports' **View Mode** itself.&#x20;

When you will open any Report with Variable enabled Custom calculations then in the View mode itself you will have **Variable** Panel on the left-hand side from where you can modify the **Variable** and run the Report to see the changes.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sprinkledata.com/product/analysing-your-data/reports/build-using-tables/advanced-features/variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
