Berserk Docs
Aggregate FunctionsStatistical

sumif

Calculates the sum of values in the group for which the predicate evaluates to true.

Equivalent to sum(iff(predicate, val, 0)) but registered as an aggregate so it composes with summarize directly.

Like sum, the value argument must be numeric or timespan. The output type follows the input type (int/longlong, realreal, timespantimespan).

Syntax

sumif(val, predicate)

Parameters

Prop

Type

Returns: long

Syntax

sumif(val, predicate)

Parameters

Prop

Type

Returns: long

Syntax

sumif(val, predicate)

Parameters

Prop

Type

Returns: real

Syntax

sumif(val, predicate)

Parameters

Prop

Type

Returns: timespan

Examples

Example 1

datatable(warrior:string, voyages:long, elite:bool)[
  "Ragnar", 42, true,
  "Bjorn", 31, true,
  "Floki", 12, false,
  "Ivar", 35, true,
  "Harald", 25, false
]
| summarize sumif(voyages, elite)
sumif_voyages (long)
108

Example 2

datatable(region:string, raid:string, silver:long, successful:bool)[
  "England", "Lindisfarne", 500, true,
  "Francia", "Paris", 7000, true,
  "England", "York", 1200, false,
  "Francia", "Rouen", 3000, true
]
| summarize sumif(silver, successful) by region
region (string)sumif_silver (long)
England500
Francia10000

On this page