How do I perform weighted calculations in Looker Studio?

I’ve just started using Looker Studio. My data is collected through GA4. There’s a field called “licenseNum” that’s a number, and “eventCount” is the number of system events. The data is roughly as shown in the table below.

I want to add a statistical summary chart to show the weighted average, that is, the result of (1×100+3×124+5×23+6×20)÷(100+124+23+20)

How can I do this?

I’ve tried several methods provided by Chat GPT and Gemini, but none of them work.

licenseNum eventCount
1 100
3 124
5 23
6 20

I think you could do this with a pair of calculated fields.

First, you need a calculation (say WeightedValue) to get the weighted value of each licenseNum times eventCount. Then you’ll have a column with the values 1*100, 3*123, 5*23, 6*20.

Then, create a second calculation that sums the first calculation and divides it by the sum of the event count. That would look like: SUM(WeightedValue)/SUM(eventCount).

I think that should do it!