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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
JustinShultz
Frequent Visitor

Weighted Average Based on Multiple Critera and Filters

Hello Power Bi Community,

 

I am new to Power Bi and trying to understand how to do a fairly complex DAX calculation. I have several weighted averages I would like to calculate but the denomanator is changing based on several criteria. Heres a short snippet of my example. 

 

Project NameSectorReporting Year% SavingsArea
Project 1HE201950100000
Project 2GO20193250000
Project 3GO20194375000
Project 4HE20192835000
Project 1HE202053100000
Project 2GO20203650000
Project 3GO20204575000
Project 4HE20202835000

 

The numbers I am trying to calucalte include:

Area Weighted % Savings by Reporting Year = % Saving * Area / SUM(Area by Reporting Year)

Area Weighted % Savings by Reporting Year and Sector = % Savings * Area / SUM(Area by Reporting Year and Sector)

 

My method so far as been to create individual columns for each of these steps. 

Area by Year = CALCULATE(SUM('Table'[Area]), ALLEXCEPT('Table','Table'[Reporting Year]))
  • Which creates a column of the summed area for the same year of the Reporting Year
  • I tried using a measure and then having the sum filtered on the Report tab based on removing all other Reporting Years but this did not change the SUM. 

 

I then setup Area by Reporting Year and Sector, one per column:

HE Area by Year = CALCULATE(
SUM('Table'[Area]),
ALLEXCEPT('Table','Table'[Reporting Year]),
'Table'[Sector]="HE")
  • This step was repeated for each of the different sectors and has become quite tedious and difficult to manage when creating graphics on the Report tab.

 

I then use each of these in the denomenator of the Area Weighted % Savings equation. With the number calculated I'm creating visualizations in the Report tab and trying to filter by Reporting Year and Sector. 

 

I believe there is some way I can get the SUM Total Area by Report Year, Sector, and other criteria without creating so many columns. Is there an easier way to do this with a DAX equation? 

6 REPLIES 6
lbendlin
Super User
Super User

You don't really want to use columns for that.  Transform them to measures.

 

When you create your DAX formula, use copious amounts of variables to validate that your intermediate steps do what you want.  Since in DAX everything is a table (just sometimes a single row/single column table), use CONCATENATEX to visualize your intermediate results.

 

An example for the first measure would be

 

% by year =
var y = selectedvalue('Table'[Reporting Year])
var s = SELECTEDVALUE('Table'[% Savings])*SELECTEDVALUE('Table'[Area])
var t = CALCULATE(sum('Table'[Area]),Filter(ALL('Table'),'Table'[Reporting Year]=y))
var r = divide(s,t)
return r
 
This is a bit excessive but it demonstrates the general approach.

Hello @lbendlin, thank you for your reply. I was not aware that you can use var to hold variable information. I have two follow up questions to expand my understanding for more applications.

  1. How would I expand the FILTER() or other functions to include additional critera? For example, while keeping the year filter, I can then add a filter for the sector like "HE" or "GO"? I would like to do another weighted average based on each year and each sector.
  2. I am having trouble using the measure to visualize values over multiple years. I am creating a scatter plot but the measure only displays the last year of results, instead of the result for each year. Even when using a visualization filter, results are not shown for 2019, only 2020. How do I display the measure results spread out for each year in a scatter plot?

Thank you for taking the time to help me with my beginner questions. 

1. yes, CALCULATE() and many other functions accept multiple filters that are ANDed together. You can als use &&, || and IN for more elaborate filters (at a storage engine performance cost).  Check the documentation for detailed syntax.

2. "it depends" - do you want the year as an attribute in the scatter, or do you want to ignore it?

 

2. I would like the year as an attribute. I would like to display the results for the measure based on the results of year [Reporting Year]. So the % of Year measure is on the Y-axis and Reporting Year is on the X-axis. 

That would give you a scatter plot with vertical columns of dots for each year. Are you sure you want that?

I believe I mis-understand then. Below are two images of what I'm working with.

 

The first is close to what I want but the orange dot is the measure we created, notice it's only on 2021. 

 

The second graphic is the measure on a scatter plot by itself. 

 

This is what I want but the orange dot spread across the years.This is what I want but the orange dot spread across the years.This is what I got instead.This is what I got instead.

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.

Top Solution Authors