---
title: .sumPercent()
slug: sumpercent
docTags: 
createdAt: 2021-09-14T18:35:54.000Z
---

Sums each grouped item in a [Sequence](docId\:JG4itlQWafzLpArttFo67) or [List](docId\:xWH_cUkHj9waqaEfb7H71), 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()](docId:-ljO-INA1ggCdfQJrWvAf)  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.

