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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

Calculate average based on filter selected

Hi All, 

 

My original dataset has 14 rows and 2 column Company and Gender. 

 

Column_1 = CALCULATE(COUNTROWS(Sheet1),ALLEXCEPT(Sheet1,Sheet1[Company]))

Column_2 = CALCULATE(COUNTROWS(Sheet1),ALLEXCEPT(Sheet1,Sheet1[Gender],Sheet1[Company]))

Column_3 = DIVIDE(Sheet1[Column_2],Sheet1[Column_1])

 

I want to calculate Average Column, which is average of of Male and Female from column 3.

For Male it should be (.50+.29+.67)/3 =48.41 % 

 

How can i evaluate Average Column. Please guide. Thanks a Lot

 

cmp.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Habib : Just realised the solution with Measure

 

Measure_1 = CALCULATE(COUNTROWS(Sheet1),ALLEXCEPT(Sheet1,Sheet1[Company]))

Measure_2 = COUNTROWS(Sheet1)

Measure_3 = [Measure_2]/[Measure_1]

 

Measure_4 = CALCULATE((AVERAGEX(SUMMARIZE(Sheet1,Sheet1[Company]), [Measure_3]) ),ALLEXCEPT(Sheet1,Sheet1[Gender]))

 

No Need to create additional table as i did before. Thanks

View solution in original post

3 REPLIES 3
Habib
Continued Contributor
Continued Contributor

Hi @Anonymous,

 

Average can be calculated using below formula, but in your scenario, it will not give you correct answer always.

 

Avg = CALCULATE(AVERAGE(Sheet1[Column_3]),ALLEXCEPT(Sheet1,Sheet1[Gender]))

As you mentioned that result should be 48.41% but if you actually calculate % of M among your dataset, it should be 43% consiering your have 6 records for M. Better would be calculate the % using below DAX without involving the Column_3.

 

NewAvg = SWITCH(Sheet1[Gender],"F",COUNTAX(FILTER(Sheet1, Sheet1[Gender]="F"),Sheet1[Gender])/COUNTA(Sheet1[Gender]),"M",COUNTAX(FILTER(Sheet1, Sheet1[Gender]="M"),Sheet1[Gender])/COUNTA(Sheet1[Gender]))

Hope this will help you.

Anonymous
Not applicable

@Habib :  I can't consider 6 records as i have to filter the record (i.e. summarize 1 row for each [company & Gender]).

So if you see my filter table it has only 3 rows for male and 3 rows for female based on company & Gender.

Column_1 is number of rows for a particular company and Column_2 is number of Female or Male in that company. 

 

In your solution , i will always have total number of rows for Female or Male from full table. 

 

I found the solution : What i did , i created a New Table from the filtered table and then applied average and counta functiona to get the result

 

I am still not sure , if i dont create a New Table , how can i get 3 records using DAX. Thanks

 

 

Anonymous
Not applicable

@Habib : Just realised the solution with Measure

 

Measure_1 = CALCULATE(COUNTROWS(Sheet1),ALLEXCEPT(Sheet1,Sheet1[Company]))

Measure_2 = COUNTROWS(Sheet1)

Measure_3 = [Measure_2]/[Measure_1]

 

Measure_4 = CALCULATE((AVERAGEX(SUMMARIZE(Sheet1,Sheet1[Company]), [Measure_3]) ),ALLEXCEPT(Sheet1,Sheet1[Gender]))

 

No Need to create additional table as i did before. Thanks

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors