OpenBI Docs Buy

List.Sum

The total of a list of numbers or durations, nulls left out.

Group: List. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

List.Sum(list as list, optional precision as nullable number) as any
ParameterTypeDescription
listlistNumbers, or durations; nulls are skipped.
precisionnullable number
optional
Precision.Double (the default) adds as double-precision numbers; Precision.Decimal as decimals.

Returns

any. A number for numbers, a duration for durations; null when the list has no value but null.

Remarks

  • An empty list, or one of nulls only, sums to null, not 0. Wrap it in if ... = null then 0 else ..., or use List.Sum(list) ?? 0, when you need a zero.
  • Numbers and durations do not mix: a list with both is an error.
  • With Precision.Decimal each number is taken as the decimal Power Query shows for it (15 significant digits) and the total is exact before it becomes a number again: amounts such as 0.1 and 0.2 add up to 0.3.

Examples

An order's total

List.Sum({120, 80, null, 45.5})
245.5

Hours on a job

List.Sum({#duration(0, 1, 30, 0), #duration(0, 2, 15, 0)})
#duration(0, 3, 45, 0)

Amounts added as decimals

List.Sum({0.1, 0.2}, Precision.Decimal)
0.3

Without the precision the total is 0.30000000000000004.

List.Average, List.Product, List.Accumulate, Value.Add.

Last updated · OpenBI Studio 0.3.79