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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Calculate average across all categories without showing empty categories

Hi all,

 

I am using a visual to show average times per category (bars) as well as an overall average across ALL categories (dotted line). Please see screenshot below.

 

Screenshot 2020-10-28 154656.jpg

I am using a Measure to calculate the overall average (dotted line):

 

Overall Avg = CALCULATE(SUM('Table1'[Work Time])/COUNT('Table1'[Number]),ALLSELECTED('Table1'))

 

 

The calculation works fine. However, the problem is that the ALLSELECTED() function always returns also empty categories (see Category D). Especially when there are more empty categories, this looks really ugly.

 

I already tried using ALL(), ALLEXCEPT(), etc. instead of ALLSELECTED() without success. Also, "Show items with no data" is disabled.

 

Any ideas how to fix that? Thanks a million!

4 REPLIES 4
AntrikshSharma
Super User
Super User

@Anonymous  Create a separate measure for total work time:

Total Work Time = SUM ( 'Table1'[Work Time] )

The try this:

Overall Avg =
CALCULATE (
    DIVIDE ( [Total Work Time], COUNT ( 'Table1'[Number] ) ),
    FILTER ( VALUES ( 'Table'[Category] ), [Total Work Time] <> 0 )
)

 Here is a visual from my dummy data:

1.PNG2.PNG

Anonymous
Not applicable

@AntrikshSharma Thank you for your help.

 

If I use your approach, I get the average value per category instead of an overall average across the categories (see below). The empty category is not visible now!

 

Screenshot 2020-10-29 095725.jpg

 

Not sure if this is important, but the value of my cateogries is not actually 0. Instead, the "empty" categories are hidden due to some applied filters.

amitchandak
Super User
Super User

@Anonymous , Try if this can work

Overall Avg = CALCULATE(SUM('Table1'[Work Time])/COUNT('Table1'[Number]),filter(ALLSELECTED('Table1'), not(isblank(Table[category]))))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak Thank you for your fast reply.

 

Unfortunately, this doesn't work as well. Same result.

 

In addition, I want to use this Measure for different "Category" columns. Hence, it should be as generic as possible and I intended not to use the "Category" column itself in the Measure. It might be possible workaround of course... 🙂

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.