cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Community Champion

@Anonymous

Using this sample table:

With this dax you have the average:

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

All SelectedA & B Selected

Lima - Peru
5 REPLIES 5
Community Champion

@Anonymous

Using this sample table:

With this dax you have the average:

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

All SelectedA & B Selected

Lima - Peru
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

Microsoft Employee

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]

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!