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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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