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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
capko
Helper II
Helper II

Compute weighed average by month

Hello,

 

I'm trying to find the way to do the following problem on PBI (I'm still pretty new). Let's say that I have the following table:

 

IDQuantityPriceMonthYear
1507.512023
2202.532023
1107.012023
35030.022023
157.612023
1107.722023
31520.022023
2103.022023
215.022023

 

This table will represent the price of sold items (1, 2, 3) in differents months taking into account the quantities and unitary prices. I would like to compute the weighted average of each one of the items by month.

 

I created a table with disticnt elements but I don't know how to calculate this weighted average...

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @capko 

 

You can try the following methods.

Measure = Var _N1=MAX('Table'[Price])*MAX('Table'[Quantity])
Var _N2=CALCULATE(SUM('Table'[Quantity]),ALLEXCEPT('Table','Table'[ID],'Table'[Year],'Table'[Month]))
Return
DIVIDE(_N1,_N2)

vzhangti_0-1697010800059.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @capko 

 

You can try the following methods.

Measure = Var _N1=MAX('Table'[Price])*MAX('Table'[Quantity])
Var _N2=CALCULATE(SUM('Table'[Quantity]),ALLEXCEPT('Table','Table'[ID],'Table'[Year],'Table'[Month]))
Return
DIVIDE(_N1,_N2)

vzhangti_0-1697010800059.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Greg_Deckler
Super User
Super User

@capko There is a weighted average quick measure or you may find this helpful as well: Better Weighted Average per Category - Microsoft Fabric Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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