Setup Calculations
Learn the basic math tag patterns for numbers, dates, conditions, and null-safe output.
What You'll Learn
In this tutorial, you'll build a quote summary that uses calculation tags to produce clean numeric and date output. By the end, you'll know how to:
Calculate a deposit amount with
<MATH>Calculate a remaining balance from the same source field
Add days to a date with
type="date"Use a calculation result inside conditional logic
Prevent blank numeric fields from causing errors
What You'll Build
An Opportunity quote summary that includes:
The opportunity amount
A 10% deposit amount
A remaining balance
A follow-up date 30 days after close
A manager review note for larger deals
Estimated time: 15 minutes
Prerequisites
Before starting, ensure you have:
Access to S-Docs Templates in Salesforce
Permission to create or edit templates
An S-Docs template related to
OpportunityA test opportunity with values in
AmountandCloseDateBasic familiarity with merge fields such as
{{!Opportunity.Amount}}
If you are brand new to S-Docs syntax, complete a basic merge field tutorial first.
If you insert fields with the field picker, remove any auto-added number or date formatting before using those fields inside <MATH> tags.
Step 1: Open or Create Your Template
Start with an Opportunity template where you want to show calculated values.
Navigate to S-Docs Templates in Salesforce
Open an existing template or click New Template
Choose
Opportunityas the related objectOpen the template editor
Click Source if you want to paste the syntax directly
You now have a place to add calculation tags.
Step 2: Add Your First Calculation
Add a quote summary section with a 10% deposit calculation.
What you just did:
Used
<MATH>to multiply the opportunity amount by0.10Added
format-number="#,###.00"for commas and two decimalsKept the original field visible for comparison
Step 3: Add the Remaining Balance
Now calculate the amount left after the deposit.
What you just did:
Subtracted the deposit from the full amount
Used parentheses so the deposit is calculated first
Kept spaces around operators so S-Docs reads the math correctly
Step 4: Add a Date Calculation
Use a date calculation when you need a due date, reminder date, or follow-up date.
What you just did:
Started the expression with a date field
Added
type="date"so S-Docs treats the expression as date arithmeticFormatted the result as a readable date like
April 23, 2026
Step 5: Use a Calculation Inside Conditional Logic
You can evaluate a calculated result before showing a message.
Add this block below the quote summary:
What you just did:
Calculated the remaining balance inside the condition
Compared that result to
10000Rendered the note only when the threshold is passed
Step 6: Make the Calculation Safe for Blank Values
Blank numeric fields can cause Invalid double and related errors.
Use replaceall to substitute a blank value with 0.
What you just did:
Replaced a blank amount with
0Protected the math expression from null-style numeric errors
Created a pattern you can reuse with optional numeric fields
Step 7: Save and Test Your Template
Now test the calculation output with a real opportunity.
Click Save in the template editor
Generate the template from an opportunity with
AmountandCloseDateCheck the deposit, remaining balance, and follow-up date
Test again with a larger amount to trigger the manager review note
What to verify:
The deposit shows 10% of the opportunity amount
The remaining balance equals the amount minus the deposit
The follow-up date is 30 days after close
The manager review note appears only when the balance is above
10000
Step 8: Try a DOCX Variation
If your template format is DOCX, wrap the full math expression in square brackets.
What changed:
The calculation uses bracketed Microsoft template syntax
The full math block stays inside the brackets
The same formula logic still applies
Common Issues and Solutions
Issue 1: "The result does not show commas or decimals"
Problem: The number calculates, but the output is not formatted.
Solution:
Add
format-numberon the<MATH>tag itselfUse a pattern like
#,###.00Regenerate the document after saving the change
Issue 2: "I get an Invalid double error"
Problem: One of the numeric fields in the expression is blank.
Solution:
Replace blank values with zero using
replaceall=" ,0"Test the source record to confirm the numeric field has data
Apply the same null-safe pattern to every optional numeric field in the calculation
Issue 3: "Date math fails with a date format error"
Problem: S-Docs does not recognize the first value in the expression as a date.
Solution:
Make sure the expression uses
<MATH type="date">Start the expression with a date field such as
{{!Opportunity.CloseDate}}If you use a static value, format it as
yyyy-MM-dd
Issue 4: "The subtraction result looks wrong"
Problem: The total does not match the expected deposit or balance.
Solution:
Add parentheses around the inner calculation
Keep spaces around operators like
+,-,*, and/Test the deposit formula by itself before combining it with a second expression
Issue 5: "The manager review note never appears"
Problem: The conditional block stays hidden even for large deals.
Solution:
Check the threshold value in the
RENDERconditionConfirm the calculation returns a number before the comparison
Test the same calculation outside the conditional block first
What You've Learned
Congratulations! You've built a template with calculation tags and learned:
✅ How to calculate a percentage with <MATH>
✅ How to calculate a remaining balance from one field
✅ How to add days to a date with type="date"
✅ How to use a math result inside RENDER logic
✅ How to prevent blank-value errors with replaceall
Next Steps
Now that you've mastered the basics, you can:
Expand Your Calculations
Add tax, subtotal, or discount calculations
Build date offsets for reminders and due dates
Reuse the same calculation pattern in other template sections
Combine with Other Features
Add conditional messages with How to Show or Hide Content Automatically
Reuse queried values with Advanced Data Pulling (For Admins)
Format related output with How to Format Text, Dates, and Currency
Practice More
Add a late-fee calculation to an invoice template
Show approval language only above a calculated threshold
Build due-date logic for contract follow-up steps
Practice Exercise
To reinforce what you've learned, build an invoice-style Opportunity template that includes:
A subtotal based on
Opportunity.AmountA 7% tax calculation
A final total that adds subtotal and tax
A payment due date 14 days after
CloseDateAn approval note that appears only when the final total is greater than
25000
Bonus challenges:
Make every numeric field null-safe
Add a second threshold message for totals above
50000Convert one calculation to DOCX syntax
Last updated
Was this helpful?

