Loading
Salesforce Enforces New Security Requirements in Summer 2026Read More
Tableau Semantics
Best Practices When Writing Formulas

Best Practices When Writing Formulas

The formula syntax affects the way the formula is queried.

When writing a formula, use these syntax rules.

  • Use the correct functions as described in Adding Functions.
  • Surround fields in the formula by brackets.
  • Use the correct operator syntax
  • Use the correct literal expression syntax
    • Numeric literal expressions are written as numbers. For example, 1.3567.
    • String literal expressions are written with quotation marks. For example, “Unprofitable”.
    • Date literal expressions are written with the # symbol. For example: #August 22, 2024#.
    • Null literal expressions are written as “null”.
    • Tableau Semantics uses Tableau literal expressions. Learn more about literal expressions in the Tableau Literal expression syntax documentation.
  • Use the correct date function syntax:
    • Date functions are hardcoded in ISO format:
      • Date: "yyyy—MM—dd" or "yyyymmdd" or "yyyy—MM" OR “yyyy”
      • Time:
        • Hh:mm:ss
        • Hh:mm:ss.sss
        • HH:mm:ss.SSSSSS
        • Hh:mm:ssZZZZ
        • Hh:mm:ssSS.ZZZZZ
        • "T[hh][mm][ss]"
        • "T[hh]:[mm]:[ss] "
        • “T[hh]:[mm]:[ss]ZZZZZ”
      • Datetime: "<date>T<time>" or "<date> <time>" or "<date>’T’<time>"
      • Examples:

        "2020—02—08T09"

        "2020—02—08 09"

        "2020—02—08 09:30:26"

        "2020—02—08 09:30:26.123"

    • Use DATEPARSE for other formats.
  • Use the correct comment syntax
    • To enter a comment in a calculation, type two forward slashes: //
    • Multiline comments can be added by typing /* to start the comment and */ to end the comment.
    • Example of a formula with comments:
      SUM([Sales]) / SUM([Profit])
      
      /*John's calculation
      
      To be used for profit ratio
      
      Do not edit*/
      
 
Loading
Salesforce Help | Article