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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate average and include blanks

Hi all,

I can't figure out the correct DAX function to use for this calculation so hopefully someone can point me the right way.

 

Below is a screenshot of what I'm trying to achieve.  It's actually a pretty simple calculation; I need at the end of the Grand total for each category, the average total for each.  So as the examples show,  the Tables category has a grand total of 28 over a 10 month period so I need the average to be 2.8.  However, there are some months where this is blank (I createad a measure to assign a 0 value in those cases) but Power BI won't include the blank months in the calculation.  In my example Power BI shows the average as 5.6.

 

I'm hoping someone can un-dumb my brain please!  Thanks in advance for your help.

 

Avg totals.png 

10 REPLIES 10
ZEB
Frequent Visitor

I have encountered a similar scenario where Power BI's AVERAGEX()  is excluding blank and nulls from average calculation. 

Average Opportunities = AVERAGEX(
                               KEEPFILTERS(ALL(CalendarTable[Week Start Date])),
                               [Opportunities]
)

 

How can I modify my measure to include these blank or null values when calculating the average?

I've shared the link to the pbix file for reference. Any guidance on this would be greatly appreciated.

Thank you!

 

ZEB_0-1699479439223.png

 

Matrix Average.pbix

 

@Ashish_Mathur @dsalony @SOppeneer @v-yuezhe-msft 

SOppeneer
Frequent Visitor

@ZEB The approach I took was manually taking the sum of values divided by the count of values and blank values, so something like: SUM([values]) / ( COUNT([values]) + COUNTBLANK([values]) ). This would be in your CALCULATE function with appropriate filters. I suppose in your case this would then be the sum of [Opportunities] divided by the appropriate number of days from your CalendarTable.

SOppeneer
Frequent Visitor

I know the post is very old (2017), but I stumbled upon it when looking into the same issue.

 

The difference between Excel and Power BI is that Power BI ignores blanks and zeros when calculating the average while Excel does not. There might be a better way, but I was able to solve it by manually calculating the average as the sum of values divided by the count of elements. 

 

Note: The column you use for the count should not include blanks, otherwise you need to ensure Power BI also counts the blanks (e.g. COUNT + COUNTBLANK). Then in Power BI it would become: SUM([values]) / ( COUNT([values]) + COUNTBLANK([values]) ).

 

average include zero.jpg

Ashish_Mathur
Super User
Super User

Hi,

 

What formula have you written for computing the average?


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

Here are the different measures I have:

1)  COUNT OF CATEGORY:  IF(COUNT('MyTable'[CATEGORY])=Blank(), 0, COUNT('MyTable',[CATEGORY]) 

2) NUMBEROFMONTHS: DISTINCTCOUNT(Date_Dim(MONTHNAME_YEAR)

3) GRAND TOTAL OF CATEGORIES:  SUMX('MyTable',[COUNT OF CATEGORY]

4) AVERAGE:  CALCULATE ([GRAND TOTAL OF CATEGORIES]/NUMBEROFMONTHS)

 

The AVERAGE measure works if there's a 'true' value for that month/year.  It seems when I artificially add that 0 value (in the COUNT OF CATEGORY measure) it still ignores it.

 

Thanks!

Hi,

 

Share the link from where i can download your file.


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

Hi

Unfortunately I can't share the file due to HIPAA laws.  I had to change the actual categories in my screenshot example.  This is the best data set I can give so I'm hoping someone can still help me figure this out.

@Anonymous,

Does your original table look like below? If so, create the measure that calculate month number using this DAX: NUMBEROFMONTHS = MONTH(MAX(MyTable[Date])), then you will get correct average value.

1.JPG

However, if the above DAX doesn't help, please post table structure and share dummy data in your table for us to analyze.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I have the same issue... my time period however is daily.  I tried this formula but substituted DAY func for MONTH, but it did not work.  This should be so simple to do (it is in Excel), but I cannot figure this out... in table below, I need to return the 2nd average colulmn, not the first which is what I am getting by default with PowerBI

 

            Day Count10
 People Visiting the Building   
BuildingDay 1Day 2Day 3Day 4Day 5Day 6Day 7Day 8Day 9Day 10 Ave (ignore blanks)Ave (over all 10 days)
Building A45493844523146482837 41.8041.80
Building B4  7  3 911 6.803.40
Building C  1        1.000.10
Building D56673 4565 5.224.70
Building E   3  1    2.000.40
Total54554561553154534353 50.4050.40

 

 

Hi,

 

Share the link from where i can download your PBI file.


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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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