all = countries
.select({ country_code: "code" })
.join_left(
medals
.groupby(["code", "country"])
.rollup({ quantity: (d) => op.sum(d.quantity) }),
"code"
)
.impute({ quantity: () => 0 })
.derive({
share: (d) => d.quantity / op.sum(d.quantity)
})
.orderby(aq.desc("quantity"))
.derive({
cumshare: aq.rolling((d) => op.sum(d.share)),
row: op.row_number()
})