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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
SushiAddict
Frequent Visitor

Taking an average by category without ignoring row context

Hello, I'm looking to produce a calculated measure that is able to return an average for the category that the row item is in. See example below:

 

ColorSale IDSale PriceAverage by Color
Green11015
Green21015
Green32015
Green42015
Yellow525
Yellow685
Yellow755
Blue83040
Blue95040

 

I'm essentially looking for the DAX version of the "AverageIF" function in excel. While I am able to create a summary table displaying the colors and average by colors, that is not what I am trying to achieve. The table needs to be displayed as above, with the individual sales included. Is there a way for CALCULATE to generate a filter context based on the row context of each item?

 

Any help is appreciated!

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

CALCULATE(AVERAGE(Table[Sales]),ALLEXCEPT(Table,Table[Color]))

View solution in original post

2 REPLIES 2
wdx223_Daniel
Super User
Super User

CALCULATE(AVERAGE(Table[Sales]),ALLEXCEPT(Table,Table[Color]))

Thank you, this does what I had requested. I have hit another issue, if you are able to answer this question as well:

 

I will need this data displayed on a line graph where the data from column 'color' is not displayed. In effect, the table would look like this:

 

IDPriceAverage by Color
11015
21015
32015
42015
525
685
755
83040
95040

 

With the above solution, the calculated measure doesn't work if the 'color' column isn't in the graphic, even though the relationship exists in the data table. Do you know of a way around this?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.