> You are reading the Docusign Developer Documentation. For clean Markdown of any page, append .md to the page URL.
>
> Documentation indexes by section:
> - APIs and SDKs: https://docusign.docs.buildwithfern.com/docs/llms.txt
> - Platform 101: https://docusign.docs.buildwithfern.com/platform/llms.txt
> - Extension Apps: https://docusign.docs.buildwithfern.com/extension-apps/llms.txt
> - Docusign CLI: https://docusign.docs.buildwithfern.com/docusign-cli/llms.txt
>
> Authentication (OAuth, JWT Grant, M2M): https://docusign.docs.buildwithfern.com/platform/auth
> Webhooks and Connect: https://docusign.docs.buildwithfern.com/platform/webhooks
>
> OpenAPI specifications: https://docusign.docs.buildwithfern.com/openapi.json
> MCP server: https://docusign.docs.buildwithfern.com/_mcp/server

# Calculated fields

> Describes how to use fields to calculate and display formulas in a document.

## Calculated fields

You can use *calculated fields*, also known as *formula tabs*, to apply a formula to user input from other tabs and to display a calculated final result. If the values of the tabs providing input to the calculated field change, the value of the calculated field will also change.

Calculated fields have a type of `formulaTab`, and can draw their input from [number fields](/docs/esign-rest-api/esign101/concepts/tabs/number-fields), `dateTabs`, and `dateSignedTabs`. A calculated field must draw its input exclusively from number fields or `dateTabs/dateSignedTabs`; it cannot accept both numeric and date values at the same time.

## Numeric formulas

To set the numeric formula of a calculated field, and to specify its inputs, you set its formula property and enter the mathematical formula to be used, specifying the `tabLabels` of the `inputTabs` to be used as variables.

For example, the following code demonstrates how to use a numeric formula to calculate the total price of an object by adding the amount of tax. The subtotal is entered in one tab, and another read-only tab supplies the tax rate.

```text
{
    "tabs": {
        "numberTabs": [{
            "tabLabel": "subTotal",
            ...
        }, {
            "tabLabel": "tax",
            "value": "0.05",
            "locked": "true",
            "xPosition": "50",
            "yPosition": "100",
            "documentId": "1",
            "pageNumber": "1"
        }],
        "formulaTabs": [{
            "tabLabel": "calculatedPrice",
            "formula": "([subTotal] * [tax]) + [subTotal]",
            "xPosition": "80",
            "yPosition": "100",
            "documentId": "1",
            "pageNumber": "1"
        }]
    }
}
```

## Date formulas

You can perform date-time operations and create formulas using a set of predefined date functions. You can use the following date-related functions to create date formulas:

* `AddDays(d1,n1)`: Returns a date calculated by adding or subtracting a number of days **(n1)** to or from a date **(d1)**. To subtract, a minus sign (-) is used before **(n1)**.
* `AddMonths(d1,n1)`: Returns a date calculated by adding or subtracting a number of months **(n1)** to or from a date **(d1)**. To subtract, a minus sign (-) is used before **(n1)**.
* `AddYears(d1,n1)`: Returns a date calculated by adding or subtracting a number of years **(n1)** to or from a date **(d1)**. To subtract, a minus sign (-) is used before **(n1)**.
* `DateDiff(d1,d2)`: Calculates the number of days between two dates **(d1-d2)**.
* `Day(d)`: Returns the current day of the month as a value, 1 through 31.
* `Days(d)`: Returns the number of days in the month for the specified date field **(d)**.

For example, if you had a contract that will be valid for 30 days, starting from the [date](/docs/esign-rest-api/reference/envelopes/enveloperecipienttabs/create#schema__enveloperecipienttabs_datesignedtabs) the document is signed, you could use the following tabs definition to calculate the contract expiration date using the `AddDays(d1,n1)` function:

```text
{
    "tabs": {
        "dateSignedTabs": [{
            "tabLabel": "todaysDate",
            ...
        }],
        "formulaTabs": [{
            "tabLabel": "contractLength",
            "formula": "AddDays([todaysDate], 30)",
            "xPosition": "150",
            "yPosition": "75",
            "documentId": "1",
            "pageNumber": "1"
        }]
    }
}
```