Sum field value by another field

I have a dataset like this:

name count
red 1
red 3
green 5
red 4
green 2
blue 6

And I want to sum “count” for each “name” like this:

name count
red 8
green 7
blue 6

How can I do that ? reduce or something else ?

Use group() and sum():

import "array"

array.from(rows : [
{name : "red", count : 1},
{name : "red", count : 3},
{name : "green", count : 5},
{name : "red", count : 4},
{name : "green", count : 2},
{name : "blue", count : 6}])

|> group(columns: ["name"])
|> sum(column: "count")
|> group()

Result:

1 Like