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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
haoqizha
Frequent Visitor

Weighted Average Price calculation - with multiple filters

Hi,

 

I have got below tables:

 

ClientProductSalesQTYAUPMonth Year
AABC$10050$2Aug 2022
BABC$24060$4Aug 2022
AABC$5005$10July 2022
BABC$30010$3July 2022

*AUP is Average Unit Price: Sales/QTY

 

So what I am trying to get is a Weighted Average of AUP within a certain Month Year for a given Product:

 

In Aug, the Weighted Average price for product ABC = (100/340) *2 + (240/340)*4

In July, the Weighted Average price for product ABC = (500/800) * 10 + (300/800)*3

 

Not too sure how to get this through DAX Measure?

 

 

Thanks!

 

 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @haoqizha ,

 

Approve @ddpl . Here is another measure, please try:

Measure = DIVIDE(SUMX('Table',[Sales]*[AUP]),SUMX('Table',[Sales]))

Output:

vjianbolimsft_0-1660902559097.png

If you want to apply all the columns in the table visual, please try:

Measure 2 = 
var _a = FILTER(ALL('Table'),[Month Year]=MAX('Table'[Month Year]))
return DIVIDE(SUMX(_a,[Sales]*[AUP]),SUMX(_a,[Sales]))

Output:

vjianbolimsft_1-1660902884478.png

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @haoqizha ,

 

Approve @ddpl . Here is another measure, please try:

Measure = DIVIDE(SUMX('Table',[Sales]*[AUP]),SUMX('Table',[Sales]))

Output:

vjianbolimsft_0-1660902559097.png

If you want to apply all the columns in the table visual, please try:

Measure 2 = 
var _a = FILTER(ALL('Table'),[Month Year]=MAX('Table'[Month Year]))
return DIVIDE(SUMX(_a,[Sales]*[AUP]),SUMX(_a,[Sales]))

Output:

vjianbolimsft_1-1660902884478.png

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ddpl
Solution Sage
Solution Sage

@haoqizha First create calculated column "Weighted Average" as per below

 

Weighted Average = 
var _A = CALCULATE(SUM('Table (2)'[Sales]),FILTER('Table (2)','Table (2)'[Month Year] = EARLIER('Table (2)'[Month Year])))
         var _B =DIVIDE('Table (2)'[Sales],_A)*'Table (2)'[AUP]
         return
             _B
then create visual table as per below
 
ddpl_0-1660023981966.png

 

Please accept as a solution if its worked.

haoqizha
Frequent Visitor

@ddpl  Thanks for your reply.  Can I ask why do you use "EARLIER" function here?

@haoqizha Earlier fuction we have used for grouping of the MontYear value so that we will get the total for A and B ie A = 340 and B =800 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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