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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
dgch
New Member

Weighted average formula help

Hello everyone, i need help with the weighted average formula in Power BI, let me explain:

 

I have this table:

 

Table1Table1

 

The columns are month, workcenter, rework% generated by workcenter, and the tons rework generated. I need to calculate the weighted average of rework% weighted by tons, group by month, and the result should be something like this:

 

foto2.jpg

 

Could somebody help me to achieve this, thanks 🙂

2 ACCEPTED SOLUTIONS
az38
Community Champion
Community Champion

Hi @dgch 

you could create a calculated table

Table = 
SUMMARIZE('Table','Table'[Month],
"Ton",SUM('Table'[Ton]),
"Weighted %",DIVIDE(SUMX('Table',[Rework]*[Ton]),SUM('Table'[Ton]))
)

 

then do not forget to set Format: Percentage in Modeling ribbon for "Weighted %" field

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

JarroVGIT
Resident Rockstar
Resident Rockstar

Hi @dgch 

Please post your tables in a format so we can import it into PowerBI, not as a picture, then we can help you a lot faster.

In this case, I recreate a dummy table with the following data:

MonthWorkcenterPercentageTonnes
A110100
A215150
B15200
B210150
C11300
C22150

The numbers and stuff doesn't really matter, it is the logic that matters. You didn't specifify what you want your result to be in, so I assumed you were fine with a calculated table. The dax for this calculated table is the following:

CalculatedTable = 
VAR _weightTable = ADDCOLUMNS('Table', "weight", DIVIDE([Tonnes], CALCULATE(SUM('Table'[Tonnes]), FILTER('Table', 'Table'[Month] = EARLIER('Table'[Month])))))
RETURN
SUMMARIZE(_weightTable, 'Table'[Month], "WeightedAveragePercentage", SUMX(FILTER(_weightTable, [Month] = EARLIER([Month])), [weight] * [Percentage]), "Tonnes", SUMX(FILTER(_weightTable, [Month] = EARLIER([Month])), [Tonnes]))

In the first VAR, I take the original table and add a weight column per month. In the RETURN section, I create a summary table based on month by summing the weight*percentage column and summing the tonnes column. This result in the following table in Power BI:

image.png

This is correct according to my manual calculations in Excel 🙂 

Let me know if this answers your question!

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
JarroVGIT
Resident Rockstar
Resident Rockstar

Hi @dgch 

Please post your tables in a format so we can import it into PowerBI, not as a picture, then we can help you a lot faster.

In this case, I recreate a dummy table with the following data:

MonthWorkcenterPercentageTonnes
A110100
A215150
B15200
B210150
C11300
C22150

The numbers and stuff doesn't really matter, it is the logic that matters. You didn't specifify what you want your result to be in, so I assumed you were fine with a calculated table. The dax for this calculated table is the following:

CalculatedTable = 
VAR _weightTable = ADDCOLUMNS('Table', "weight", DIVIDE([Tonnes], CALCULATE(SUM('Table'[Tonnes]), FILTER('Table', 'Table'[Month] = EARLIER('Table'[Month])))))
RETURN
SUMMARIZE(_weightTable, 'Table'[Month], "WeightedAveragePercentage", SUMX(FILTER(_weightTable, [Month] = EARLIER([Month])), [weight] * [Percentage]), "Tonnes", SUMX(FILTER(_weightTable, [Month] = EARLIER([Month])), [Tonnes]))

In the first VAR, I take the original table and add a weight column per month. In the RETURN section, I create a summary table based on month by summing the weight*percentage column and summing the tonnes column. This result in the following table in Power BI:

image.png

This is correct according to my manual calculations in Excel 🙂 

Let me know if this answers your question!

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks!!! 🤗

az38
Community Champion
Community Champion

Hi @dgch 

you could create a calculated table

Table = 
SUMMARIZE('Table','Table'[Month],
"Ton",SUM('Table'[Ton]),
"Weighted %",DIVIDE(SUMX('Table',[Rework]*[Ton]),SUM('Table'[Ton]))
)

 

then do not forget to set Format: Percentage in Modeling ribbon for "Weighted %" field

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Thanks for the help 🤗

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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