# How calculate a weighted average in Groupyby ?

Hello,

I’m a new user of KNIME and I need a help to calculate an average.

Indeed, I have a data with sales and price for each city and I would like to group the citys by country and calculate the average of the price.

Country Product City Sales Price
Allemage D Berlin 85 635
US A Californie 147 1006
UK B Fulham 64 704
UK A Liverpool 28 1006
UK A London 360 1006
France C Lyon 75 314
UK E Manchester 40 1153
France E Marseille 118 1153
Italy E Milano 126 1153
Allemage A Munich 59 1006
UK A Newcastle 73 1006
US A NY 133 1006
France B Paris 47 704
Italy A Rome 114 1006
Italy D Torino 34 635
UK E Tottenham 129 1153

When i calculate the weighted average for country, I should get this result

Country Average price
UK 1014
US 1006
Espagne 704
France 803
Allemage 787
Italy 1028

But with a group by node, the sales are not considerated in the aggregation of the average.

1. Before use Math Formula node to multiply sales by price
2. Group by Country new product column with sum and Sales column wits sum aggregation.
3. Use Mat formula again to divide sum of products with sum of Sales.
3 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.