Cumulate
Arithmetic functions cumulate
syntax
- cumulate(a)
- cumulate(a, relation)
definition
- cumulate(a) results in an Attribute with the cumulation of the non Null values of attribute a.
- cumulate(a, relation) results in an attribute with the cumulation of the non null values of attribute a, grouped by the relation. The Domain unit of the resulting attribute is the values unit of the relation attribute.
description
- For domain units with Index numbers starting from 0 (default), cumulate(const(1, domainunit, uint32)) - 1 is synonym for Id(domain unit). It is advised to use the id function in such a case.
- There is no id(domainunit, relation) function, use cumulate(const(1, domainunit, uint32), relation) - 1 to calculate index numbers for each entry in the relation domain.
applies to
- Attribute a with Numeric Value type
- Relation attribute with value type of the group CanBeDomainUnit
conditions
- The Values unit of the resulting Data item should match with regard to value type and Metric with the values unit of attribute a.
- The domain unit of arguments a and relation must match.
A partial sum that does not fit the value type of a is an error, as it is for Sum: cumulate of a uint8 attribute [200, 100] stops with Failed to convert 300 to unsigned char, because 300 does not fit a uint8. Where the sums can be that large, cumulate a wider value type instead.
since version
6.061
example
1. attribute<uint32> cumulateNrInh (City) := cumulate(City/NrInhabitants);
2. attribute<uint32> cumulateNrInhRegion (City) := cumulate(City/NrInhabitants, City/Region_rel);
| City/NrInhabitants | City/Region_rel | cumulateNrInh | cumulateNrInhRegion |
|---|---|---|---|
| 550 | 0 | 550 | 550 |
| 525 | 1 | 1075 | 525 |
| 300 | 2 | 1375 | 300 |
| 500 | 1 | 1875 | 1025 |
| 200 | 3 | 2075 | 200 |
| 175 | null | 2250 | null |
| null | 3 | 2250 | 200 |
domain City, nr of rows = 7