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
minhquankhong
Frequent Visitor

How to set up weighted average for multiple years

I have set up measures to get the percentage of total foreign sales over total gross income for 2007 - 2013. However, I do not know how to set up the weighted averages. Below are examples of my questions and weighted averages. These weighted averages need to be in the same dashboard. Thank you for your help.

 

2007 86%

2008 87%

2009 89%

2010 90%

2011 91%

2012 92%

2013 88%

 

Weighted average 1 = (2007+2008+2009)/(2007+2008+2009)

Weighted average 2 = (2008+2009+2010)/(2008+2009+2010)

Weighted average 3 = [(2009+2010)/(2009+2010)]*2/3 + [2011/2011]*1/3

Weighted average 4 = [2011/2011]*1/3 + [(2012+2013)/(2012+2013)]*2/3

1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi, @minhquankhong 

 

It’s my pleasure to answer for you.

According to your description,I think you can create four measures to calculate the desired result.

Like this:

weighted average4 = var a=CALCULATE('Measures 1'[% of AFBI/Total Income],'PL_Domestic Entitiies'[Year]="2011")
var aa=CALCULATE('Measures 1'[Total AFBI],'PL_Domestic Entitiies'[Year]="2011")
var b=CALCULATE('Measures 1'[% of AFBI/Total Income],'PL_Domestic Entitiies'[Year]="2012")
var bb=CALCULATE('Measures 1'[Total AFBI],'PL_Domestic Entitiies'[Year]="2012")
var c=CALCULATE('Measures 1'[% of AFBI/Total Income],'PL_Domestic Entitiies'[Year]="2013")
var cc=CALCULATE('Measures 1'[Total AFBI],'PL_Domestic Entitiies'[Year]="2013")
return DIVIDE(c*cc+b*bb,c+b)*DIVIDE(2,3)+DIVIDE(a*aa,a)*DIVIDE(1,3)

7.png

Here is my sample .pbix file.Hope it helps.

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-janeyg-msft
Community Support
Community Support

Hi, @minhquankhong 

 

It’s my pleasure to answer for you.

According to your description,I think you can create four measures to calculate the desired result.

Like this:

weighted average4 = var a=CALCULATE('Measures 1'[% of AFBI/Total Income],'PL_Domestic Entitiies'[Year]="2011")
var aa=CALCULATE('Measures 1'[Total AFBI],'PL_Domestic Entitiies'[Year]="2011")
var b=CALCULATE('Measures 1'[% of AFBI/Total Income],'PL_Domestic Entitiies'[Year]="2012")
var bb=CALCULATE('Measures 1'[Total AFBI],'PL_Domestic Entitiies'[Year]="2012")
var c=CALCULATE('Measures 1'[% of AFBI/Total Income],'PL_Domestic Entitiies'[Year]="2013")
var cc=CALCULATE('Measures 1'[Total AFBI],'PL_Domestic Entitiies'[Year]="2013")
return DIVIDE(c*cc+b*bb,c+b)*DIVIDE(2,3)+DIVIDE(a*aa,a)*DIVIDE(1,3)

7.png

Here is my sample .pbix file.Hope it helps.

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Janey,

 

Sorry for the late reply. I was out of the office last week and in training the whole time this week. I tested your solution. It worked. Thank you so much for your help.

minhquankhong
Frequent Visitor

@amitchandak attached is the link to sample file. Thank you.

 

Example File 

amitchandak
Super User
Super User

@minhquankhong , the same data does seem to be inline with what you are asking

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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.