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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Weighted Average Selling Price based on volume and volume remaining

I'm trying to create the DAX to write a funtion for weighted average selling price based on the volume and the volume remaining on a contract.


I have lots of dimension filters that can be adjusted.  

  • Company
  • Location
  • Contract
  • Customer
  • Item
  • Item Group
  • Contract Type
  • Sales Rep
  • Start Date
  • End Date

 

And then I have my measures:

  • Price
  • Volume
  • Balance
  • Balance %

 

I'm minimize the table to show the important items, but all of my dimensions listed above are columns in the table.

 

ContractCustSelling PriceWeighted Avg Price (Vol)Weighted Avg Price (Bal)VolumeVolume BalanceBalance %
33033744597.882.5757894740.8348473553510720%
31517595063.6610.608956227.5661267443388149144%
363664544106.451.5341785542.33349940229327594%
19383390185.3213.5597107716.261468313231239174%
33943313887.2212.3729719.647964932884282698%
26441902991.1211.5636792915.369463532580211682%
264443732108.266.752271528.319062575126896476%
290924970131.3923.6153005424.874551613654237565%
29090595060.117.3829153960249700%
 Total/Average 92.378888989.9657717795.206982033012545 62%

 

Selling Price: Average calculates correctly. = 92.3788889

Total Volume = 20330

Balance = 12545

Balance % = 62%

 

I don't know to calculate the DAX is for these two measures:

 

Weighted Average Price (Vol) = Selling Price * ( Volume / Total Volume )

Example: First Row: WAPV = 97.88 * (535 / 20330 ) = 2.575789474 

Aggregated average = 89.96577177

 

Weighted Average Price (Bal) = Selling Price * ( Balance / Total Balance)

Example: First Row: WAPV = 97.88 * (107 / 12545 ) = 0.83484735

Aggregated average bal = 95.20698

 

Any thoughts? I tried sum and sumx using ALL, ALLSELECTED and ALLEXCEPT, and tried AVERAGEX and the same, but I can't figure it out.  Thanks

4 REPLIES 4
ValtteriN
Super User
Super User

Hi,

Here is example of the logic you can use:

weighted avg = MAX('Table (8)'[Selling Price])*MAX('Table (8)'[Volume])/CALCULATE(SUM('Table (8)'[Volume]),ALLSELECTED('table (8)'))
 
By using MAX you can reference to row in the filter context:
ValtteriN_0-1643447407950.png



The logic for the (Bal) is the same.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/









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

Proud to be a Super User!




Anonymous
Not applicable

Thanks,

 

Your calculation goes beyond what I was trying to calculate but thank you.  Greatly appreciated.  

David-Ganor
Resolver II
Resolver II

Hi @Anonymous ,

Generally, only the Toal balance and Total volume should be calculated using ALL.

You should set the current values of the calculation as variables.

Something along the lines of:

Selling Price * ( Volume / Total Volume )

Var this_row_selling_price='fact_table'[selling price]

Var this_row_volume='fact_table'[volume]

Var Total_Volume=Calculate(sum ('fact_table'[volume]),ALL('fact_table'))

Return

this_row_selling_price*(this_row_volume/Total_Volume)

 

Hope it helps.

David

Anonymous
Not applicable

Thanks for the solution.

 

The variable wouldn't allow me to just pick the measure so I had to do

 

VAR this_row_selling_price = SUM( 'fact table'[selling price] ) and
VAR this_row_volume = SUM( 'fact table'[volume] )

 

It makes the total come out to 7.7 Million when it sould be about $311.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.