Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi all,
I have to calculate the weighted average and standard deviation of my data.
I basically have the wind farm locations, age, Generator Make, and the number of generators.
Location | Age | Generator Make | N. Generator |
A | 23.16 | Bonus | 14 |
B | 17.65 | Bonus | 21 |
C | 19.33 | Bonus | 2 |
D | 26.66 | Bonus | 26 |
E | 24.74 | Bonus | 34 |
As there might be from 1 up to 30 generators on each farm, a simple average of the age would not result in a correct indicator. I also want to know the spread of the age, hence the need to calculate the weighted standard deviation.
I can calculate the weighted average age in DAX.
I cannot find a way of calculating the weighted variance or standard deviation of the age of the turbines across the locations, as it requires the use of iterator formulae, along with either aggregator formula or measure, i.e. the calculated weighted average.
I would really like not to have to learn another language such as python and re-do the whole work.
Regards,
Pietro
Solved! Go to Solution.
Hi @Pietro
You can certainly calculate a weighted variance or standard deviation, making use of iterators.
Here is how I would create measures for this, starting from scratch. I've assumed your table is called Generators and has the columns shown in your example.
Link to the variance formula I've applied:
https://en.m.wikipedia.org/wiki/Weighted_arithmetic_mean#Frequency_weights
# Generators =
SUM ( Generators[N. Generator] )
Weighted Average Age =
VAR NumGenerators =
[# Generators]
VAR WeightedSumOfAge =
SUMX (
Generators,
Generators[Age] * Generators[N. Generator]
)
VAR Result =
DIVIDE ( WeightedSumOfAge, NumGenerators )
RETURN
Result
Weighted Variance of Age =
VAR NumGenerators =
[# Generators]
VAR WeightedAverageAge =
[Weighted Average Age]
VAR SumOfWeightedSquaredDeviation =
SUMX (
Generators,
Generators[N. Generator] * ( Generators[Age] - WeightedAverageAge ) ^ 2
)
VAR NumGeneratorsMinusOne =
NumGenerators - 1
VAR Result =
DIVIDE ( SumOfWeightedSquaredDeviation, NumGeneratorsMinusOne )
RETURN
Result
Weighted Standard Deviation of Age =
SQRT ( [Weighted Variance of Age] )
The Variance and Standard Deviation measures should produce the same result as if each generator was listed separately on its own row, and a sample variance function (VAR.S or VARX.S) was applied.
Does this work at your end?
Regards,
Owen
Hi @Pietro
You can certainly calculate a weighted variance or standard deviation, making use of iterators.
Here is how I would create measures for this, starting from scratch. I've assumed your table is called Generators and has the columns shown in your example.
Link to the variance formula I've applied:
https://en.m.wikipedia.org/wiki/Weighted_arithmetic_mean#Frequency_weights
# Generators =
SUM ( Generators[N. Generator] )
Weighted Average Age =
VAR NumGenerators =
[# Generators]
VAR WeightedSumOfAge =
SUMX (
Generators,
Generators[Age] * Generators[N. Generator]
)
VAR Result =
DIVIDE ( WeightedSumOfAge, NumGenerators )
RETURN
Result
Weighted Variance of Age =
VAR NumGenerators =
[# Generators]
VAR WeightedAverageAge =
[Weighted Average Age]
VAR SumOfWeightedSquaredDeviation =
SUMX (
Generators,
Generators[N. Generator] * ( Generators[Age] - WeightedAverageAge ) ^ 2
)
VAR NumGeneratorsMinusOne =
NumGenerators - 1
VAR Result =
DIVIDE ( SumOfWeightedSquaredDeviation, NumGeneratorsMinusOne )
RETURN
Result
Weighted Standard Deviation of Age =
SQRT ( [Weighted Variance of Age] )
The Variance and Standard Deviation measures should produce the same result as if each generator was listed separately on its own row, and a sample variance function (VAR.S or VARX.S) was applied.
Does this work at your end?
Regards,
Owen
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
7 | |
6 |
User | Count |
---|---|
14 | |
13 | |
11 | |
9 | |
9 |