How to Calculate a Weighted Average in PowerBI Using DAX

Опубликовано: 05 Август 2026
на канале: vlogize
299
like

Struggling with aggregating data in PowerBI? Learn how to calculate a `weighted average` by group using DAX formulas effectively.
---
This video is based on the question https://stackoverflow.com/q/65929237/ asked by the user 'Zabman' ( https://stackoverflow.com/u/2951506/ ) and on the answer https://stackoverflow.com/a/65946751/ provided by the user 'sergiom' ( https://stackoverflow.com/u/248949/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.

Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Get aggregate of aggregate by group PowerBI

Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.

If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Understanding the Challenge of Aggregating Data in PowerBI

PowerBI is an incredibly powerful tool for data analysis, enabling users to create insightful reports and dashboards. However, achieving accurate data representations can sometimes be a challenge, especially when it comes to aggregations.

Consider the following situation: You have a dataset that's already aggregated by supplier, month, name, location, and division, along with mean and count for each group. While the initial aggregation provides useful insights, the next logical step may be to aggregate these results further by different categories. In this particular case, we want to calculate the average of these aggregates by group, but traditional methods such as AVERAGEX might not yield the expected results.

In this guide, we’ll explore how to calculate a weighted average in PowerBI using DAX formulas to achieve the desired grouping efficiently.

The Example Data Set

Let's take a look at the initial data table you have:

MonthNameLocationDivisionMeanCountDecGlobalfGCSales42DecLocalFGCSales5.4427DecGlobalfGCPurchasing0.002DecGlobalfNCSales31You want to combine the means and counts into a new table structured by month, location, and division, resulting in the following goal:

MonthLocationDivisionMeanCountDecGCSales5.34129DecGCPurchasing0.002DecNCSales31The Problem with Averages

You might think of using AVERAGEX, but as you've discovered, it can lead to incorrect results because it simply averages the means rather than considering their respective counts. Multiplying means with their counts also doesn't solve the issue as it operates on already grouped values, leading to inaccuracies.

The Solution: Weighted Average

The solution to accurately compute the average of aggregates is to use a weighted average formula. By doing so, you can ensure that each mean value is multiplied by its respective count and then divided by the total count across the group.

The DAX Formula

To achieve this, you would implement the following DAX formula:

[[See Video to Reveal this Text or Code Snippet]]

Breakdown of the Formula

SUMX Function:

This iterates over each row in the table tbl, calculating the product of the mean and the count for each entry.

SUM Function:

This aggregates the total counts across your group.

DIVIDE Function:

Finally, it divides the sum of the products (mean multiplied by count) by the total count to give you a weighted average that accurately reflects the data.

Putting It All Together

Using this DAX formula, you will be able to create a measure that provides the desired average of means by the specified grouping – ensuring that you reflect the data accurately based on the weight of each entry.

Final Thoughts

Calculating a weighted average in PowerBI using DAX formulas can significantly enhance your data analysis capabilities. By considering both the mean and count in your calculations, you can provide deeper insights that would otherwise be lost through simpler averaging methods.

Happy Reporting!