.sumPercent()
Sums each grouped item in a Sequence or List, and returns each group's sum, as as a percentage of the overall total sum of all items.
Typically this is only used together with a .groupBy() expression, and returns an AggregatedResult that contains each group and its percentage of the total.
(If used without a groupBy, it will always return 100%)
Syntax
.sumPercent{expression}
- Evalutes expression on each item in the Sequence or List, then returns its percentage of the overall total
Examples
- [1, 2, 3, 4, 5].groupBy{it % 2 ? "Odd Numbers" : "Even Numbers"}.sumPercent{it} will return an AggregatedResult of "Odd Numbers" = 60%, "Even Numbers" = 40% (because (1 + 3 + 5) / 15 = 60%, and (2 + 4) / 15 = 40%)
- db.job.find().groupBy{department}.sumPercent{baseComp.annualized} returns all departments in the organization, grouped by by what percentage of total annualized base comp base is paid to that department.
