cancel
Showing results for
Search instead for
Did you mean:
Frequent Visitor

## Weighted Average in a Hierarchy Visualized by a Matrix

I am trying to create a measure to show the weighted average at multiple levels of a hiearchy.  I will be presenting this data in a matrix visualization in Power BI.  I will provide sample data to illustrate this in more detail.

In this example, I have three levels of the hierachy: Product; Location; and Business.

I want the average Unit Price weighted by Qty Sold.

In Excel, the results would look like this for Location:

and like this for Business:

In Power BI, the expectation is that when you collapse a level of the hierarchy in the matrix, you see the corresponding weighted average in an adjacent column.  At the lowest level you would simply show the original Unit Price per product.

Is this possible?  Is there another solution I should consider?

1 ACCEPTED SOLUTION
Super User

Try this:

``````Avg =
DIVIDE (
SUMX ( Table1, Table1[Unit Price] * Table1[Qty Sold] ),
SUMX ( Table1, Table1[Qty Sold] )
)``````

4 REPLIES 4
Super User

Try this:

``````Avg =
DIVIDE (
SUMX ( Table1, Table1[Unit Price] * Table1[Qty Sold] ),
SUMX ( Table1, Table1[Qty Sold] )
)``````

Frequent Visitor

Thank you!  This is perfect!  However, I found one anomaly during my validation--maybe you will know what is causing it.  One of the values at the lowest granularity came up as a lower value compared to the actual.  But others seemed unafflicted by this.  In this example I get ~\$87k where I would expect ~\$155k.

Super User

Is your Unit Price column using a SUM aggregation? I bet you have more than one row in your data table for 1A and it's adding the prices together like it does for the subtotals.

Frequent Visitor

You nailed it.  Duh.  I should have realized that.  I have what I need now and it's working perfectly.  Thank you so much!

## Helpful resources

Announcements

#### Check it out!

Click here to read more about the June 2022 updates!

#### Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

#### Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

#### The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors