Getting an Aggregate Amount using Sum

Doc Auto Team
Doc Auto Team
  • Updated

The sum function allows us to add up one or more number-type variables within a collection.

Syntax

Sample Transactions Data

Fiona Forrest purchases 50 Common shares for $1.00 per share

Gemma Germinate purchases 25 Common shares for $1.00 per share

Herbert Horticulture purchases 50 Common shares for $1.00 per share

Isabella Iridescence purchases 15 Common shares for $1.00 per share

Julian Juniper purchases 7 Common shares for $1.00 per share

Using sum

{collection | sum:'numberVariable'}

Since we are not opening the collection, and this is not logic, there are no {#} opening tags or {/} closing tags required.

Input {transactions | sum:'numShares'} shares are issued.
Output 147 shares are issued.

Using sum with Math Operations

You can also use math with the sum function. For more information on how to perform math operations in conjunction with the sum function, check out Math Operations through Document Coding.

{collection | sum:'numberVariable*numberVariable'}

Input The total consideration of ${transactions | sum:'numShares*pricePerShare'} is received by the Corporation.
Output The total consideration of $147 is received by the Corporation.

Using sum with Logic

You can perform logic with the outcome of a sum function. By adding logic syntax and number logic parameters, we are able to use the sum function when evaluating certain conditions. For more information on how to perform logic with number-type data, check out Conditions: IF statements.

{#(collection | sum:'numberVariable')>numericalValue}Conditional content{/}

Input A total of {transactions | sum:'numShares'} share{#(transactions | sum:'numShares')!=1}s{/} are issued.
Output A total of 147 shares are issued.