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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate the average per category

Hi,

 

i was searching yesterday within the community for a solution but did not find anything that matches my case. If this was already discussed i would be glad if somebody can piont out the post.

 

I would like to calculate the average price for different categories. The difficulity is that i have rows with different quantities. Here an example

 

lineProdcut TypeqtyTotal price
Platform 1A15€ 61.51
Production lineProduct nameqtytotal price (not price per piece)

 

I don't know how i generate the correct calculation. I want to calculate the sum of total price and devide this by the sum of qty. 

 

Here is an excerpt of the table

 

lineProdcut TypeqtyPricePrice per piece
Platform 1A15€ 61.51€ 4.10
Platform 1B14€ 60.32€ 4.31
Platform 1G21€ 60.32€ 2.87
Platform 1G42€ 58.47€ 1.39
Platform 1J33€ 58.47€ 1.77
Platform 1W49€ 139.00€ 2.84
Platform 2J15€ 281.88€ 18.79
Platform 2Q27€ 143.39€ 5.31
Platform 2R13€ 57.04€ 4.39
Platform 2H8€ 57.04€ 7.13
Platform 2F12€ 93.04€ 7.75
Platform 2B20€ 206.89€ 10.34
Platform 2B35€ 207.36€ 5.92
Platform 2C25€ 126.34€ 5.05
Platform 2R24€ 126.34€ 5.26
Platform 3T39€ 131.94€ 3.38
Platform 3O2€ 138.16€ 69.08
Platform 3P47€ 56.24€ 1.20
Platform 3Y44€ 64.48€ 1.47
Platform 3W43€ 253.28€ 5.89
Platform 3R20€ 282.25€ 14.11
Platform 3D27€ 210.94€ 7.81

 

These are the average values that i would like to calculate:

 

LineTotal QtyTotal PriceAverage
Platform 1174€ 438.09 €      2.52
Platform 2179€ 1,299.32 €      7.26
Platform 3222€ 1,137.29 €      5.12

 

I am sure that there is a pretty easy solution which i did not consider. 

 

Thanks for you help!

1 ACCEPTED SOLUTION

Which calculations you have used.

In case you have used this, hope you created it is a measure, not Column

 

divide(sum(price),sum(qty))

 

Please share the formula you created. It should be dynamic. Unless there is join missing.  Or Interactions are off.

 

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

Try like

divide(sum(price),sum(qty))

 

This will adjust according to the group by.

In case you need a category level fixed. try

https://community.powerbi.com/t5/Desktop/Calculate-Average-per-category/td-p/362637

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Anonymous
Not applicable

Thanks for you answer. 

 

Using the solution mentioned in the provided link i get the correct calculation. The problem now is that the calculation seems to be static. 

 

I have data from several months. If i select now a single month in my report the calculation does not adjust. 

 

Is it possible to create a dynamic calculation?

Which calculations you have used.

In case you have used this, hope you created it is a measure, not Column

 

divide(sum(price),sum(qty))

 

Please share the formula you created. It should be dynamic. Unless there is join missing.  Or Interactions are off.

 

Anonymous
Not applicable

Thank you!

 

Using a measure instead of a column was the solution. 

 

Like I said ... the answer was very simple. 

 

I think i need to go back an review the differences between measures and columns.

 

Thanks again for the responses!

Columns are pre-calculated.  You can see them in the table view. And the measure is calculated run time. means there will impact of data grouping.

 

For Multiple-use, We typically use column A*B and then SUM. This means we need a column. Sales Amount= QTY* Price and then Sum(Sales Amount)

For Divide, we need to do Sum(A)/Sum(B). Discount % = Sum(Discount)/Sum(Sales)*100. Means we need measure.

 

Refer the pbix on this article - https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.