# Using Spreadic Formulas

You may have noticed by now that every time you run a Tabular Data or Pivot Data query, a formula is generated in the cell you select. In fact, you can copy this Spreadic formula to another cell or make certain changes to the formula - just like how other standard spreadsheet formulas work!&#x20;

### Tabular Data - the `SPD_FETCH` Function

Each parameter of the function corresponds to one section of the UI in the `Tabular Data` mode (and in the exact same order). For example, the first parameter of the function is the name of the model, whereas you are asked to choose a model from the list in the top section of the UI in [Your First Spreadic Query](https://spreadic.gitbook.io/product-docs/quickstart-guide/your-first-spreadic-query).&#x20;

Other parameters work rather similarly, with the only point to note about syntax is the use of hash (#) as a separator whenever there are multiple selected fields or filtering / ordering conditions. There is also a prompt that helps you with the general syntax of the formula.

<figure><img src="https://849799185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FezRwkAMDQoGABh7UHyjF%2Fuploads%2FuQeLZwWDtVvsYVhfgm4m%2FScreenshot%202022-12-19%20at%2016.47.06.png?alt=media&#x26;token=94f43555-ae32-4613-99f5-04fbdf1d042e" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The field names used in Spreadic Formulas are always in their original format (i.e. as in a SQL query).&#x20;
{% endhint %}

{% hint style="info" %}
If you are familiar with SQL, you may choose to input filtering conditions (in the appropriate SQL dialect) directly into the place for filter parameter. &#x20;

There is also a way to retrieve the actual SQL query generated by the Spreadic formula, which could be useful for troble-shooting any errors. Simply input `SPD_RETRIEVESQL(your SPD_FETCH parameters)` into another cell, and the SQL query will be returned.
{% endhint %}

### Pivot Data - the `SPD_PIVOT` Function

This function again works in sync with the `Pivot Data` mode - the parameters are in the same order as the input prompts in the UI.&#x20;

{% hint style="info" %}
There is also a `SPD_RETRIEVEPIVOTSQL` function that works similarly to retrieve the SQL query generated by the Spreadic function.
{% endhint %}

### Cell Referencing

The example below shows how you can, say, reference a spreadsheet cell as an input to the filter parameter:

<figure><img src="https://849799185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FezRwkAMDQoGABh7UHyjF%2Fuploads%2F4mEMT5GsfhuvdR9pCwUs%2FScreenshot%202022-12-19%20at%2016.49.30.png?alt=media&#x26;token=ddb718f8-24ba-4053-bc0f-dece77047994" alt=""><figcaption></figcaption></figure>
