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! Request now

Reply
emilmorkeberg
Frequent Visitor

Averagex not working when calculating 'days with sales'

Hi!

Im trying to calculate an average measure per SKU (called "Productivity"). However, when I'm not selecting any SKU, the Averagex-measure leaves me with the "NaN" error. I really hope someone can help me, as I struggle to find a proper solution.

 

Average Productivity per SKU =

AVERAGEX(
    KEEPFILTERS(VALUES('Item'[Item Number Name])),
    CALCULATE([Productivity per SKU])
)

The measure above works perfectly fine when I highlight/select a specific SKU from a visual. However, when I don't select a SKU I receive the 'NaN' error. I have found out the reason is the '# Days w Sales' in the 'Productivity per SKU'-measure, as I can replace it with a random number and all the calculations seem to work fine with no errors.
 
Productivity per SKU =
[Sales] / [# Days w Sales] / [# Stores w Sales]

I use the following measure to calculate the numbers of days with sales. I have also tried others like DISTINCTCOUNT and likely:
 
# Days w Sales =
CALCULATE(COUNTROWS('Date'),FILTER(Sales,[Sales] > 0))
 
So TLDR;
Do you have any alternative ways to calculate # Days w Sales that will work with my Averagex calculation Average Productivity per SKU? Please let me know if I need to explain further or if you need any other info in order to solve the problem.
 
Thank you in advance!
1 ACCEPTED SOLUTION
emilmorkeberg
Frequent Visitor

Turns out there were missing days/stores for some items in the calculation and thus the error.

IFERROR solved the problem fine.

View solution in original post

3 REPLIES 3
emilmorkeberg
Frequent Visitor

Turns out there were missing days/stores for some items in the calculation and thus the error.

IFERROR solved the problem fine.

Anonymous
Not applicable

Hi @emilmorkeberg ,

 

Typically you get NaN when you try to calcualte 0/0

use  divide operator.PNG

 

So we recommend that you use the DIVIDE function whenever the denominator is an expression that could return zero or BLANK.

 

For your case, i think the DAX you used for [# Days w Sales] is fine, just try to  use DIVIDE() instead of /  

=DIVIDE( DIVIDE([Sales] / [# Days w Sales]), [# Stores w Sales] )

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@emilmorkeberg , if sales is measure , prefer

 

CALCULATE(COUNTROWS('Date'),FILTER(values('Date'[Date]),[Sales] > 0))

 

 

Also use the divide function

 

example 

 divide(divide([Sales], [# Days w Sales]),[# Stores w Sales])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors