Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join 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.

Reply
Pietro
New Member

Power Bi mix calculation between aggregators and iterators

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.

 

LocationAgeGenerator MakeN. Generator
A23.16Bonus14
B17.65Bonus21
C19.33Bonus2
D26.66Bonus26
E24.74Bonus34

 

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

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

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


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

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


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.