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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Tevon713
Helper IV
Helper IV

Average if non zero of measure

Hi all,

 

I need help in attempt transform excel model into power bi. Created the calc measure to count. The trouble lie in seeking the average if non zero of this calc measure. Got an error message stating function AVERAGEX cannot work with values of type Boolean. Maybe I'm overthinking something. Thank you.

 

Excel Model

CountIF=COUNTIF(B5:B39,"<>0")

AverageIF=AVERAGEIF(B5:B39,"<>0",B5:B39)

 

Tevon713_0-1761690349124.png

 

PowerBi Model

Ct _Measure = CALCULATE(COUNT(Data[Trn Units]),FILTER('Data',Data[Claim]="Y" && Data[Name]="GeneralName"))

Avg _Measure = CALCULATE(AVERAGEX(VALUES('Data'[Acct]),([Ct _Measure]<>0 || [Ct _Measure]<>BLANK())))

 

Tevon713_3-1761691064032.png

 

 

 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Tevon713 

You are getting that error because you are trying to compare a measure against 0 and that comparison returns  a boolean value which cannot be included in the expression.

 [Ct _Measure] <> 0 || [Ct _Measure] <> BLANK ()

 Try the following

Avg _Measure =
AVERAGEX ( VALUES ( 'Data'[Acct] ), IF ( [Ct _Measure] <> 0, [Ct _Measure] ) )

 CALCULATE is not necessary as it is implicitly applied. AVERAGEX  ignores blanks.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

8 REPLIES 8
danextian
Super User
Super User

Hi @Tevon713 

You are getting that error because you are trying to compare a measure against 0 and that comparison returns  a boolean value which cannot be included in the expression.

 [Ct _Measure] <> 0 || [Ct _Measure] <> BLANK ()

 Try the following

Avg _Measure =
AVERAGEX ( VALUES ( 'Data'[Acct] ), IF ( [Ct _Measure] <> 0, [Ct _Measure] ) )

 CALCULATE is not necessary as it is implicitly applied. AVERAGEX  ignores blanks.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thank you all especially @danextian your solution make the most sense as currently set up in my data flow.

Hi @danextian.
If I have another measure similar to Ct _Measure just it Sum_Pmt and if I wanted to distinct count those acct whose Sum_Pmt <> 0 or blank. Error message "function placeholder has been used in a true/false in a table filter expression". What am I doing wrong here?

 

Sum_Pmt= CALCULATE(COUNT(Data[Payments]),FILTER('Data',Data[Claim]="Y" && Data[Name]="GeneralName"))

Ct _Acct =CALCULATE(DISTINCTCOUNT(Data[Acct]),
VAR _maxValue = [Sum_Pmt]
RETURN _maxValue <>0
)

 

Hi,

Try this measure

Measure = countrows(filter(values(Data[Acct]),[sum_pmt]<>0))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you @Ashish_Mathur. It work!!!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Shahid12523
Community Champion
Community Champion

Avg_Measure =
AVERAGEX(
VALUES(Data[Acct]),
VAR x = CALCULATE(COUNT(Data[Trn Units]), FILTER(Data, Data[Claim] = "Y" && Data[Name] = "GeneralName"))
RETURN IF(x <> 0, x)
)

Shahed Shaikh
parry2k
Super User
Super User

@Tevon713 try this:

 


Avg _Measure = AVERAGEX(VALUES('Data'[Acct]),[Ct _Measure])


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.