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
Anonymous
Not applicable

HOW TO COMPUTE AVERAGE OF VALUE FILTERED BY TWO CATEGORIES AS CALCULATED COLUMN - NOT MEASURE

Hi everyone,

 

I am having issues in computing the average of a value by filtering by two categories.

 

I have already tried a couple of solutions found in similar posts but nothing seems to work. The one that was close, but not good enough (the results were not always correct) was the following:

 

 

=CALCULATE(AVERAGE(Table[GROSS_YIELD]),ALLEXCEPT(Table,Table[CATEGORY_1],Table[CATEGORY_2]))

 

 

Also, for the scope of the work i cannot use measures because the results have to be summarized in a new column of my dabatase, that works like this:

IDCATEGORY_1CATEGORY_2GROSS_YIELDAVG_GROSS_YIELD
Product1a

x

10%20%
Product2by5%7,5%
Product3ay20%15%
Product4bx5%5%
Product5ay10%15%
Product6by10%7,5%
Product7ax30%20%

 

Ultimately, the point is to have a new column in my db where the average of gross yield is filtered by the two categories (so that when two or more products have the same categories i can see the same result).

Thanks to anyone who can help!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

To everyone who can be ineterested, I had an error in my db so the formula:

=CALCULATE(AVERAGE(Table[GROSS_YIELD]),ALLEXCEPT(Table,Table[CATEGORY_1],Table[CATEGORY_2]))

Works perfectly

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

To everyone who can be ineterested, I had an error in my db so the formula:

=CALCULATE(AVERAGE(Table[GROSS_YIELD]),ALLEXCEPT(Table,Table[CATEGORY_1],Table[CATEGORY_2]))

Works perfectly

 

 

amitchandak
Super User
Super User

@Anonymous , Try like

CALCULATE(AVERAGEX(Table,Table[CATEGORY_1] =earlier(Table[CATEGORY_1]) && Table[CATEGORY_2]=earlier(Table[CATEGORY_2])) Table[GROSS_YIELD])

 

 

Also, check if CATEGORY_1 and CATEGORY_2 is not making a unique combination

Anonymous
Not applicable

I tried what you suggested (added a comma before the value): 

CALCULATE(AVERAGEX(Table,Table[CATEGORY_1] =earlier(Table[CATEGORY_1]) && Table[CATEGORY_2]=earlier(Table[CATEGORY_2])), Table[GROSS_YIELD])

but the ouput is an error as EARLIER refers to a previous row that does not exist, i guess it has something to do with unique combinations of the two categories

 

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.