# Calculate circular references (Xcircular\_switch)

Spark supports circular references - with just a few steps, you can enable a circular reference in your Excel file to run within your Spark Service.

## File requirements

### Circular Switch

Spark requires files to have a "circular switch" included within your circular reference to enable Spark to properly trigger the calculation.

A "circular switch" acts as toggle that can turn the circular reference on or off. This helps stabilize the circular reference in Excel, and allows Spark to similarly activate the circular reference upon calculation. You can find an example of a circular switch below. Circular wwitches should be set up as Boolean values, and are recommended to be set to a `TRUE` value upon compile. &#x20;

### Setup a Circular Switch

Setting up a circular switch can be done in a few short steps:

1. Using the name manager, name a blank cell with the named ranger `XCircular_Switch` and set the value to `TRUE`.
2. Next, find your circular reference, and select any cell within the loop, and update your formula to only run the circular reference when your circular switch is equal to `TRUE`.&#x20;

<figure><img src="/files/Jr1N1ybP5CPJg7Lpgegs" alt=""><figcaption></figcaption></figure>

### Iterative calculation settings

1. Spark can match the iterative calculation settings in your workbook upon compile.
2. You can check your iterative calculation settings in Excel via: *File* -> *Options* -> *Formulas*.
   1. Note: To enable circular references in Excel, the *Enable iterative calculation* setting must be checked.
   2. By default, Excel will set `Maximum Iterations` to `100`, and `Maximum Change` to `0.001`.
   3. **Note**: Spark will only match iterations to a max of `250`. If maximum iterations in the workbook are above `250`, they will be defaulted to `250` upon upload. If *Enable iterative calculation* is not checked at time of upload, then Spark will default `Maximum Iterations` to `100` and `Maximum Change` to `0.001` in the Spark service.

<figure><img src="/files/5wxDXU9iQA4qFP3Mb5Rp" alt=""><figcaption></figcaption></figure>

### Upload your file to Spark

Upon uploading your file to Spark, the compiler will detect your circular switch and circular references, and notify you that there is a circular reference in your workbook. It will also provide information on the maximum iterations and maximum change for the circular reference in your compiled service.

{% code overflow="wrap" %}

```
INFO: Cell Sheet1!B2: INFO: Circular references detected in workbook. Spark will process the circular references with the following settings: max iterations 100, max change 0.001.
```

{% endcode %}

## **Example of `XCircular_Switch` mapping**

This service can be uploaded to Spark to use as a simple example.

{% file src="/files/SmM9riGG1QjlckkPPFEJ" %}


---

# 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.coherent.global/build-spark-services/other-mapping-options/calculate-circular-references-xcircular_switch.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.
