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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
JulietZhu
Helper IV
Helper IV

Issue about average excluding 0's

I have 15 pyaments and 10 are non-zero payments. I need calculate average for non-zero payments

 

Actul average = 45895.35/10   = 4589.535.

 

But when I used DAX formula as below. It counts 22 rows and gives me average for non-zero payment is 2086.15.

Please help. Thanks

 

Avg_NonZero_Payment_Amt = CALCULATE(AVERAGE(Measure]),FILTER(Measure,Measure[Payment_Amt]<>0))

 CountRows = Calculate(countrows(Measure), FILTER (Measure,Measure[Payment_Amt]<>0))

Capture.PNG

1 ACCEPTED SOLUTION
v-sihou-msft
Microsoft Employee
Microsoft Employee

@JulietZhu

 

I guess your Payment_Amt may have multiple entries for same date. That's the reason why it will count 22 rows for dates.

 

In this scenario, you should build a "Total Payment_Amt" measure, then write your CountRows measure like: 

 

CountRows =
CALCULATE (
    COUNTROWS ( VALUES ( Measure[Date] ) ),
    FILTER ( VALUES ( Measure[Date] ), [Total Payment_Amt] <> 0 )
)

And you need to use Total Payment_Amt divided by CountRows. 

 

Or you can try to replace those 0s with BLANK(). Average() function will ignore empty cells automatically.

 

Regards,

View solution in original post

4 REPLIES 4
Roseventura
Responsive Resident
Responsive Resident

Thank you v-sihou-msft!  I was having this same issue and this solution was exactly what I was looking for!

 

 

v-sihou-msft
Microsoft Employee
Microsoft Employee

@JulietZhu

 

I guess your Payment_Amt may have multiple entries for same date. That's the reason why it will count 22 rows for dates.

 

In this scenario, you should build a "Total Payment_Amt" measure, then write your CountRows measure like: 

 

CountRows =
CALCULATE (
    COUNTROWS ( VALUES ( Measure[Date] ) ),
    FILTER ( VALUES ( Measure[Date] ), [Total Payment_Amt] <> 0 )
)

And you need to use Total Payment_Amt divided by CountRows. 

 

Or you can try to replace those 0s with BLANK(). Average() function will ignore empty cells automatically.

 

Regards,

 

When I just use 15 rows as data source and rowcount=10. (1st screenshot) But with my original data source, the rowcount =22 (2nd screenshot).  I checked orignal data in sql server and indeed they are 22 rows (3rd screenshot)

 

Here is my two questions.

 

1) Does powerbi sum the payment based on each day already? I think it does

 

2) I do need sum them based on each day, then filter based on sum(payment_Amt)<>0. Which DAX formula should I use? Thanks.

 

 

Capture.PNGCapture1.PNGCapture2.PNG

 

Greg_Deckler
Community Champion
Community Champion

You can't really do it that way. Your measure is 0 in the context of the row of your table visualization but not in just any context. You will need to probably do a SUMMARIZE and then take the average. See this design pattern here:

 

https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon & SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.