cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gorgiRankovski Helper II
Helper II

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

Accepted Solutions
Vvelarde Community Champion
Community Champion

Re: DAX - Add average of all rows as a separate column

@gorgiRankovski

 

Using this sample table:

 

With this dax you have the average:

 

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

 

1.pngAll Selected2.pngA & B Selected




Lima - Peru

View solution in original post

5 REPLIES 5
IvanMislav Helper I
Helper I

Re: DAX - Add average of all rows as a separate column

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.

gorgiRankovski Helper II
Helper II

Re: DAX - Add average of all rows as a separate column

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

Moderator v-yuezhe-msft
Moderator

Re: DAX - Add average of all rows as a separate column

Hi @gorgiRankovski,

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.
gorgiRankovski Helper II
Helper II

Re: DAX - Add average of all rows as a separate column

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!

Vvelarde Community Champion
Community Champion

Re: DAX - Add average of all rows as a separate column

@gorgiRankovski

 

Using this sample table:

 

With this dax you have the average:

 

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

 

1.pngAll Selected2.pngA & B Selected




Lima - Peru

View solution in original post

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors