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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors