Runtime verified Test scripts included

Syntax

Subtract(minuend, subtrahend)  →  number
2 arguments — exactly

Parameters

Name Type Required Description
minuend string | number Yes Value to subtract from
subtrahend string | number Yes Value to subtract

Example

%%[
  VAR @remaining
  SET @remaining = Subtract(100, 15)
]%%
Remaining: %%=v(@remaining)=%%

Renders Remaining: 85.

A result below zero is returned as-is, so subtract in the order you want the sign to come out:

%%[
  VAR @balance
  SET @balance = Subtract(AttributeValue("Credit"), AttributeValue("Spent"))
]%%

Return value

number — the difference of the two operands.

Every successful call rendered a bare numeric literal. There is no closed set of status tokens or sentinel values.

Behaviour

Decimals and negative results work as expected. Subtract(1.5, 2.25) gives -0.75; Subtract(-5, 3) gives -8. A result below zero is returned normally, not clamped.

Numeric strings are accepted. Subtract("50", "15") gives 35, and mixing forms as in Subtract("9", 4) gives 5.

Non-numeric input aborts the page. A non-numeric string (Subtract("abc", 1)) and a boolean-like string (Subtract("true", 1)) each abort the CloudPage with HTTP 422, discarding all output rendered before the call. Neither is coerced.

Show test script
%%[
  VAR @b
  SET @b = RequestParameter("b")

  /* safe sweep: everything here is accepted and can share one request */
  IF @b == "safe" THEN
    OutputLine(Concat("Subtract(50,15)=[", Subtract(50,15), "]"))
    OutputLine(Concat("Subtract('50','15')=[", Subtract("50","15"), "]"))
    OutputLine(Concat("Subtract('9',4)=[", Subtract("9",4), "]"))
    OutputLine(Concat("Subtract(1.5,2.25)=[", Subtract(1.5,2.25), "]"))
    OutputLine(Concat("Subtract(-5,3)=[", Subtract(-5,3), "]"))
  ENDIF

  /* each risky branch aborts the page: the start marker never renders */
  IF @b == "few" THEN
    OutputLine(Concat("few start"))
    OutputLine(Concat("Subtract(1)=[", Subtract(1), "]"))
    OutputLine(Concat("few done"))
  ENDIF

  IF @b == "many" THEN
    OutputLine(Concat("many start"))
    OutputLine(Concat("Subtract(1,2,3)=[", Subtract(1,2,3), "]"))
  ENDIF

  IF @b == "str" THEN
    OutputLine(Concat("str start"))
    OutputLine(Concat("Subtract('abc',1)=[", Subtract("abc",1), "]"))
  ENDIF

  IF @b == "bool" THEN
    OutputLine(Concat("bool start"))
    OutputLine(Concat("Subtract('true',1)=[", Subtract("true",1), "]"))
  ENDIF
]%%

Availability

Platform Available
Marketing Cloud Engagement Yes
Marketing Cloud Next Yes, from API 67.0

See also