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
Sidhu
Frequent Visitor

Getting Average based on Category and Countries

I have data in the the below format. I'm trying to get the average of SpareParts by Total, If I select a Location like DEF, it needs to get all the locations in that sector which is AB and also only the locations belongs to the same category which is A here. So it needs to eliminate line I from the result set. And it should do an average of (25% + 55%+ 3% + 50%) which is 33.25%

I am using this formula which is not getting the right result.

 

Here is the demo file.

 

Inventory Average =
Var Category1 = CALCULATE(MAX('FACT'[Category]),Line[Location]=SELECTEDVALUE(Line[Location]))
Var Sector= CALCULATE(MAX(Line[Sector]),Line[Location]=SELECTEDVALUE(Line[Location]))
var test =  CALCULATE(AVERAGEX('FACT',
                          SUM('FACT'[SpareParts])/SUM('FACT'[Total])
                          ),'FACT'[Category]=Category1,Line[Sector]=Sector,ALL('FACT')
                )
 
return test

Sidhu_0-1688155019797.png

 

1 REPLY 1
AlanFredes
Resolver III
Resolver III

Hi Sidhu,

Try this. It will calculate the average correctly depending on the filterd data, as shown in the table you have.

AlanFredes_0-1688266353635.png

 

AVERAGE has the bad habit of not calculating correctly when applying filters.
See this forum post for more detail.

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.