You can increment values in the accumulator of a reduce operation, and you can then add these to the structured data plan f the output. There are some examples in the MuleSoft DataWeave training course
flightsInput reduce (
( flight,
acc={
american: {price: 0, count: 0},
delta: {price: 0, count: 0},
united: {price: 0, count: 0}
}
) ->
flight.airlineName
match {
case american if(lower(american) contains "amer") ->
acc - "american" ++ american: {
price: acc.american.price + flight.price,
count: acc."american".count + 1
}
case delta if(lower(delta) contains "del") ->
acc - "delta" ++ delta: {
price: acc.delta.price + flight.price,
count: acc."delta".count + 1
}
case united if(lower(united) contains "uni") ->
acc - "united" ++ united: {
price: acc.united.price + flight.price,
count: acc."united".count + 1
}
else -> acc
}
)
This creates a data structure with the three different key performance indicators:
