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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Twitter
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
Twitter
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors