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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

DAX - Add average of all rows as a separate column

Hi guys, I think I have a pretty basic question, but I can't figure it out. Let's say I have the following data:

 

Product      Price

A                 12
B                 15
C                 22

The average of the price is 16.33. I want to add this as a separate column to all the rows like this:

Product      Price   Average Price

A                 12      16.33
B                 15      16.33
C                 22      16.33

From here on, I would make a new column, called ScaledPrice that would be Price / Average Price like this:

 

Product      Price   Average Price    Scaled Price

A                 12      16.33                 0.73
B                 15      16.33                 0.92
C                 22      16.33                 1.35


I've been strugling with coming up with the Average Price. Somehow, I keep ending with the same value as the Price in each row. I tried with this:

AveragePrice =
var averageAll = CALCULATE(AVERAGE([Price]); ALLSELECTED('SalesTable'))
return averageAll

When I add this measure by it self (no other fields), it gives me the correct result, but when I drag the product name along with it, the measure is calculated for each row and average of one price is the same value.

 

Thanks!

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@Anonymous

 

Using this sample table:

 

With this dax you have the average:

 

AveragePrice = CALCULATE(AVERAGE('Table'[Price]);ALLSELECTED('Table'))

 

All SelectedAll SelectedA & B SelectedA & B Selected




Lima - Peru

View solution in original post

5 REPLIES 5
Vvelarde
Community Champion
Community Champion

@Anonymous

 

Using this sample table:

 

With this dax you have the average:

 

AveragePrice = CALCULATE(AVERAGE('Table'[Price]);ALLSELECTED('Table'))

 

All SelectedAll SelectedA & B SelectedA & B Selected




Lima - Peru
IvanMislav
Helper I
Helper I

just add new column for average:

 

AveragePrice= AVERAGE(Table[Price])

 

and for scaled price:

 

ScaledPrice = Table[Price]/Table[AveragePrice]

 

That should be it, if I understood correctly.

Anonymous
Not applicable

Same thing. See the image, I want to have each product's price divided by 37.44 which is the average price of all products here.

 

Table

Hi @Anonymous,

Please right click your table , then choose “New column” rather than “New measure” as follows and use the following formulas. This way, you will get desired result, for more details, you can review  the example in this attached PBIX file.

AveragePrice = AVERAGE(Table1[Price])
ScaledPrice = Table1[Price]/Table1[AveragePrice]

1.PNG


Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks for your answer Lydia, this is very close to what I want.

 

But, this does average on the whole table. If I add a filter, the average number stays the same. It needs to be average from what is shown in the table.

 

Try adding a report level filter with selecting only A and B. So, exclude C and the average remains 16.33.

 

It needs to be 13.5 now.

 

Thanks!

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.