---
schema_version: "1"
id: 501e48ba4bb4961c6769046fabfa4d83bd44b01efff0cb811bab1309293dfe9b
title: Formulas in Calculated Fields
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/analytics/264-0-0/c360_a_sl_calc_fields_formula.md
canonical_url: https://help.salesforce.com/s/articleView?id=analytics.c360_a_sl_calc_fields_formula.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 07f95a7d4a31fa954e44c8377233c92fad68ee97d68d8400b3d40862147495aa
description: A formula tells the Tableau Semantics Query Generator how to calculate the fields when running queries. You can add logic on how to calculate raw data within the dimension or measure.
products:
  - Data 360
release: "264"
---
# Formulas in Calculated Fields

A formula tells the Tableau Semantics Query Generator how to calculate the fields when running queries. You can add logic on how to calculate raw data within the dimension or measure.

Formulas are the core of [calculated fields](https://help.salesforce.com/s/articleView?id=analytics.c360_a_sl_calc_fields_create.htm&release=264.0.0&type=5 "Calculated fields are fields that don't exist in the underlying data and are defined with a formula. Calculated dimensions are qualitative, categorical fields used to group, classify, and segment data. Calculated measures are quantitative, numerical fields that are aggregated."). Calculated fields have additional [settings](https://help.salesforce.com/s/articleView?id=analytics.c360_a_sl_calc_fields_calc_field_settings.htm&release=264.0.0&type=5 "Like all fields, calculated fields have a field type of dimension or measure. Depending on the field type, calculated fields have additional field settings or metadata to be configured, such as data role, aggregation type, or sentiment."), such as data type and field type, but what makes one calculated field different from another is the formula.

A calculated field contains a formula, and the formula almost always contains at least one function. These terms—calculation, formula, function—are sometimes used interchangeably, but the’re all distinct concepts. Tableau Semantics formulas are based on Tableau Classic's calculation syntax. For more information on the syntax, see [Writing Calculations in Tableau](https://help.tableau.com/current/pro/desktop/en-us/functions_operators.htm).

There are four basic components to a formula's syntax:

- **Functions**: Statements used to transform the values or members in a field. For more information on functions, see [Functions for Calculated Field Formulas](https://help.salesforce.com/s/articleView?id=analytics.c360_a_sl_calc_fields_formula_functions.htm&release=264.0.0&type=5 "Tableau semantics supports various functions in different categories.").
    
    Functions require **arguments**, or specific pieces of information. Depending on the function, arguments can be fields, literals, parameters, or nested functions.
- **Fields**: Dimensions or measures from your data source. Field names are surrounded by square brackets \[\] if they contain spaces, and may include dotted notation to indicate what data object they're from.
- **Operators**: Symbols for an operation, such as +, =, and OR.
- **Literal expressions**: Constant values that are hardcoded, such as "High" or 1,500.

Not all formulas contain all these components. Formulas can also contain **parameters**—placeholder or dynamic values—and **comments**.

For example, consider a semantic model for scheduling pets at a vet's office. There's a date field for Initial Visit but you want a calculated field to automatically find the date for a two-week followed. Use the formula:

`DATEADD('day', 14, [Initial Visit])`

Which can be broken down as:

- Function: `DATEADD`, which requires three arguments.
    - date\_part ('day')
    - interval (14)
    - date (\[Initial Visit\]).
- Field: \[Initial Visit\]
- Operators: n/a
- Literal expressions:
    - String literal: 'day'
    - Numeric literal: 14

In this example, the hardcoded constant 14 can be replaced with a parameter, which allows the user to select how many days out to look for a followup appointment.

`DATEADD('day', [How many days out?], [Initial Visit])`

- **[Write a Formula in a Calculated Field](https://help.salesforce.com/s/articleView?id=analytics.c360_a_sl_calc_fields_formula_build.htm&release=264.0.0&type=5)**  
    Formulas define how a calculated field is computed. How a formula is written is called its syntax. A formula may contain functions, fields, operators, literal expressions, parameters, or comments.
- **[Functions for Calculated Field Formula](https://help.salesforce.com/s/articleView?id=analytics.c360_a_sl_calc_fields_formula_functions.htm&release=264.0.0&type=5)**  
    Tableau semantics supports various functions in different categories.
- **[Use the DATEPARSE Function](https://help.salesforce.com/s/articleView?id=analytics.c360_a_sl_calc_fields_dateparse_functions.htm&release=264.0.0&type=5)**  
    The DATEPARSE function takes that string input and the user-specified format and returns a date field.
- **[Best Practices When Writing Formulas](https://help.salesforce.com/s/articleView?id=analytics.c360_a_sl_calc_fields_formula_best_practice.htm&release=264.0.0&type=5)**  
    The formula syntax affects the way the formula is queried.
- **[Row Count in Tableau Semantics](https://help.salesforce.com/s/articleView?id=analytics.c360_a_sl_row_count.htm&release=264.0.0&type=5)**  
    Use the auto-generated row count measure to track the number of records in a data object. Include row counts in calculated fields for further analysis, reporting, or metrics. The row count automatically adjusts when you add filters or change the dimensions.