Liquid markup can perform simple calculations in messages, letters, and portals. When the source value comes from a query export, confirm that Liquid treats the value as a number before applying a math filter.
⭐ Get Inspired
This article was adapted from a post by Technolutions staff in the Slate Community Forums' Get Inspired space. Have a great idea for a Get Inspired post? Let us know!
Example use case
A MergePublic query returns an export named scholarship_amount. A decision letter can display the yearly amount with this merge field:
You have been awarded a scholarship in the amount of ${{scholarship_amount}}.If the scholarship is renewable for four years, the letter may need to calculate the total award.
Why string values concatenate
If Liquid treats the export value as a string, using a whole number in the times filter can concatenate the value instead of multiplying it.
That is a total of ${{scholarship_amount | times: 4}} over 4 years.For example, a scholarship amount of 15000 may output 15000150001500015000.
Force a numeric calculation
Use a decimal in the multiplier to force Liquid to treat the value as a number.
That is a total of ${{scholarship_amount | times: 4.0}} over 4 years.With a scholarship amount of 15000, this outputs 60000.
Test the rendered output
Preview the message, letter, or portal content with a record that has a known value.
Confirm that the calculated result is numeric.
Apply any required formatting after confirming the calculation itself works.
For more information about displaying query exports in decision letters, see Displaying Custom Fields in Decision Letters: MergePublic Queries.