2 Replies Latest reply on Dec 1, 2016 6:17 AM by Christian Mangold

# Weighted average with different groups in a variable

Hi,

I´m needing some help.

What I want to do is calculate the weighted average of a variable.

The particularity that is complicating me, is that in the sample I have another variable that divides the values into 2 groups, therefore, some of the values of the average to calculate belong to group 1 and others to group 2.

The average of the Variable should be weighted, group 1 with 28%, group 2 with 72% and ignore null values.

Do you understand what I want to do?

Thank you.

Example:

GroupsVariable
18
25
18
29
1
27

AVG(Variable) = ((8+8) / 2) * 0.28 + ((5+9+7) / 3) * 0.72

• ###### 1. Re: Weighted average with different groups in a variable

Hi Santiago, what I'd do is first create a calculated field that holds the weights. For instance, let's call this [Weights]:

CASE [Groups]

WHEN 1 THEN 0.28

WHEN 2 THEN 0.72

END

Then, sum this:

{ FIXED [Groups] : AVG([Variable] * [Weights]) }

EDIT: I thought my original solution would work, but oddly, it doesn't. New solution posted.

2 of 2 people found this helpful
• ###### 2. Re: Weighted average with different groups in a variable

Hi Santiago, you can try also with the command INCLUDE in stead of FIXED.

2 of 2 people found this helpful