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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
vishakhawali
Frequent Visitor

Calculate Averages across Measures excluding the cell values that are Blank

Hi,

 

RollSciencePhysicsBiologyMaths
112141123
213151216
31416130
415null1417
5null17null17

 

I want to calculate the average across the columns(for each student/rollno) where Science Physics Biology Maths are my measures.

But the caveat is : if there is a blank then that doesn't go in the average.

E.g.

For roll 1 it would be (12+14+11+23)/4

For roll 5 it would be (17+17)/2

For roll 4 it would be (15+14+17)/3

For roll 3 it would be (14+16+13+0)/4

 

How can i do this in dax?

Also note that, when the cells contain 0 it should be counted in the average but not when it is blank(roll 3)

Please note that I would need the solution to be in DAX and not Power Query

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@vishakhawali 

here is a workaournd for you

avg = 
VAR _science=if(ISBLANK([science]),0,1)
VAR _physics=if(ISBLANK([physics]),0,1)
VAR _bio=if(ISBLANK([biology]),0,1)
VAR _math=if(ISBLANK([maths]),0,1)
return ([science]+[biology]+[maths]+[physics])/(_science+_physics+_bio+_math)

However, since I don't know what your data looks like. I think maybe we can create two measures instead of five.

measure = sum('Table'[value])
Measure 2 = if(ISFILTERED('Table'[class]),[measure],AVERAGEX(VALUES('Table'[class]),[measure]))

pls see the attachment below

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
ryan_mayu
Super User
Super User

@vishakhawali 

here is a workaournd for you

avg = 
VAR _science=if(ISBLANK([science]),0,1)
VAR _physics=if(ISBLANK([physics]),0,1)
VAR _bio=if(ISBLANK([biology]),0,1)
VAR _math=if(ISBLANK([maths]),0,1)
return ([science]+[biology]+[maths]+[physics])/(_science+_physics+_bio+_math)

However, since I don't know what your data looks like. I think maybe we can create two measures instead of five.

measure = sum('Table'[value])
Measure 2 = if(ISFILTERED('Table'[class]),[measure],AVERAGEX(VALUES('Table'[class]),[measure]))

pls see the attachment below

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you so much, this worked !! 🙂

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




vishakhawali
Frequent Visitor

Hey, I cant Unpivot because I have measures and I want the solution in DAX

jaideepnema
Solution Sage
Solution Sage

Hi @vishakhawali ,

First Unpivot your table as shown below:

 

jaideepnema_0-1629297375411.png

then create a measure like this:

 

Average = 

var marks=sum('Table'[Marks])

var subjectcount=CALCULATE(DISTINCTCOUNTNOBLANK('Table'[Subject]))

return DIVIDE(marks,subjectcount,BLANK())
This would give you the desired results:
jaideepnema_1-1629297482393.png

Please accept this as a solution if your question has been answered !!

Appreciate a Kudos 😀

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors