Opens in a new tab

Help · Snippet content

Calculations & Conditions

Snippets can do arithmetic with the values you type into fill-ins, and include or leave out text depending on those values.

A complete example: a quote

Quantity: %filltext:name=qty:default=1%
Unit price: $%filltext:name=price:default=25%
Subtotal: $%calc:{qty}*{price}:2%
Tax (8%%): $%calc:{qty}*{price}*0.08:2%
Total: $%calc:{qty}*{price}*1.08:2%
%if:{qty}>=10%A 10%% volume discount will be applied.%endif%

With 12 at $25, this types:

Quantity: 12
Unit price: $25
Subtotal: $300.00
Tax (8%): $24.00
Total: $324.00
A 10% volume discount will be applied.

Note the %% for a real percent sign.

Calculations: %calc

Write %calc:sum%, or %calc:sum:decimals% to fix the number of decimal places. Use {name} for the value of a fill-in called name. In the editor: Insert ▸ Calculation.

Symbol

Meaning

Example

Result

+

add

%calc:2+3%

5

-

subtract (or a negative number)

%calc:10-4%

6

* or ×

multiply

%calc:6*7%

42

/ or ÷

divide

%calc:10/4%

2.5

^

power

%calc:2^10%

1024

( )

do this part first

%calc:(2+3)*4%

20

  • Normal math order applies: ^ first, then * /, then + -. 2^3^2 is worked out right to left.

  • Decimals: without a number, whole results have no decimals and others show up to two (10/3 → 3.33, 10/4 → 2.5). With :2 you always get exactly two (5:2 → 5.00). From 0 to 10 decimals are allowed.

  • Typed values may include commas and a dollar sign: “$1,250” counts as 1250. A field that isn’t a number counts as 0.

  • If the sum can’t be worked out (a typo, or dividing by zero), nothing is typed for it.

Conditions: %if, %else, %endif

Include text only when a condition is true. %else% is optional. In the editor: Insert ▸ Condition.

%if:{condition}%text when true%else%text when false%endif%

Condition

True when

{company}

The field has a value (anything except empty, no, 0, false, or off).

{tone}=formal

The field equals “formal”. Text comparisons ignore capitals and accents.

{tone}!=formal

The field is anything but “formal”.

{qty}>5, {qty}<5

Greater than / less than.

{qty}>=5, {qty}<=5

At least / at most.

If both sides are numbers they’re compared as numbers; otherwise as text. An optional section (%fillpart) counts as yes when checked and no when not. {clipboard} works too.

Examples

%fillpopup:name=Greeting:Formal:Casual%
%if:{Greeting}=Formal%Dear %filltext:name=Name%,%else%Hi %filltext:name=Name%!%endif%

%filltext:name=Company%
Kind regards,
John%if:{Company}%
on behalf of {Company}%endif%

Careful: {name} is replaced only inside %calc, %if conditions and %ai. In ordinary text, use the fill-in code again. The second example therefore types the literal “{Company}”; write it as:

Kind regards,
John%if:{Company}%
on behalf of %filltext:name=Company%%endif%

Because both fields are called Company, you’re asked only once. You can put an %if inside another %if.

Related: Fill-ins · Macro Reference · AI in snippets