5 Replies Latest reply on Jul 11, 2018 7:24 AM by Shinichiro Murakami

how to do weighted average

hi i am attaching a workbook where i have location, number of customers at each location who purchases a product with total cost. i like to get weighted average cost by product for each of my locations. since i don't have the detailed customers, Tableau will do a normal average of cost. i like to get weighted average instead.

the average cost in the above case is 143.3 which is not weighted. how can i get a weighted average. Thanks

• 1. Re: how to do weighted average

Hi Tony,

Difficult to understand which weighted avg you want.

Could you give me example of expected value?

Thanks,

Shin

• 2. Re: how to do weighted average

Hi Shinichiro,

in the example above, tableau is calculating an average using sum (cost) divided by number of location so sum(120,260,50)/3 to get average cost.

i want the average cost to be weighted based on number of customers for each location. so like this: (number of customers/total number)*cost

so it will be like this: weighted average: (10/35)*120+(20/35)*260+(5/35)*50=34.28+148+7=189

i have million of rows in my workbook so so many locations and products and i can't apply the logic above to calculate a weighted average

does this make sense?

• 3. Re: how to do weighted average

HI Tony,

Hope this helps.

LOD

Overview: Level of Detail Expressions

Thanks,

Shin

• 4. Re: how to do weighted average

this is great. Thanks!

• 5. Re: how to do weighted average

Hi Tony

You are welcome.

Shin