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
J2K
Helper I
Helper I

Counting Zero-Value Measure Rows in Median Calculations

I need the median value of a column (whose value is derived from a measure).  In every attempt, it is only returning the median of rows that have a value greater than zero.

 

I have two tables, one is an "employee" table and one an "attendee" table. I have a measure that counts each time an employee is in the attendee table:

 

EE Attend = CALCULATE(COUNTROWS('Attendee_R'), FILTER('Attendee_R', 'Attendee_R'[Employee ID] = MAX(Employee_M[Employee ID]) )) + 0
 
In order to use this properly in a visual table (and receive a total at the bottom) I use this measure in the visual itself:
 
EE Attend TOT = SUMX(Employee_M,[EE Attend])
 
This allows me to use a slicer on dates, employee regions, etc., and the visual will filter based on their attendance over the selected criteria.  I need to be able to get the average and median of each column.  When I try to do that, I get the following:
 
Capture.PNG
The measure I am using to calculte averages is correct, however, the median measure ignores the zero rows and only returns a value for the rows with a number.  I have tried several different ways that I can think of to get the median, but none of them work correctly.  How would I calculate the median of the full column (including zero rows)?  Any help is greatly appreciated.
 
Thanks!
 
-Jason K.
1 ACCEPTED SOLUTION

Hi,

 

Please try this measure:

MED Col A = MEDIANX(SUMMARIZE(Employee_M,Employee_M[Employee ID],"EE",[EE Attend]),[EE])

The result shows:

3.PNG

See my attached pbix file.

 

Best Regards,

Giotto

View solution in original post

9 REPLIES 9
J2K
Helper I
Helper I

Hi All,

Thank you for your replies.  My numbers are not coming from a static table (as in @Greg_Deckler's .pbix), they are being generated by a counting measure. I would love to post a .pbix file to show this, but it does not look like I can. I have no option to add an attachment to my posts/replies.

 

Edit: Here are some screen shots that I hope will help explain this further (note that these numbers will be different from my original post).

 

Here are the two tables:

Capture1.PNGCapture2.PNG

Here is the relationship:

Capture3.PNG

The visual is a table, with two columns, the first being Employee_M[Employee ID], and the second being this measure:

EE Attend TOT = SUMX(Employee_M,[EE Attend])
 
The second part of that measure uses this measure:
EE Attend = CALCULATE(COUNTROWS('Attendee_R'), FILTER('Attendee_R', 'Attendee_R'[Employee ID] = MAX(Employee_M[Employee ID]) )) + 0
 
My median measure is:
MED Col A = MEDIANX(SUMMARIZE('Attendee_R',Employee_M[Employee ID]),[EE Attend])
 
This is the result:
Capture4.PNG

I should mention that the reason why I am not using a calculated column is that I need to be able to filter by dates.

@J2K  Most people use OneDrive or Box or some other file sharing service to share PBIX files.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Here you go:

https://www.dropbox.com/sh/e9nhfa9ct8lvgdt/AABA4QgxXplpOARmOqiK4qlpa?dl=0&preview=MedianDemo.pbix

Again, I appreciate you taking the time to look at these things.

@Greg_Deckler Here you go:

 

https://www.dropbox.com/sh/e9nhfa9ct8lvgdt/AABA4QgxXplpOARmOqiK4qlpa?dl=0&preview=MedianDemo.pbix 

 

Again, I appreciate that you take the time to look at these things.

Hi,

 

Please try this measure:

MED Col A = MEDIANX(SUMMARIZE(Employee_M,Employee_M[Employee ID],"EE",[EE Attend]),[EE])

The result shows:

3.PNG

See my attached pbix file.

 

Best Regards,

Giotto

Hi Giotto,

Thank you very much. This works perfectly.

v-gizhi-msft
Community Support
Community Support

Hi,

 

Please try to use MEDIAN function.

Like this:

10.PNG

 

Best Regards,

Giotto

Greg_Deckler
Super User
Super User

Well, all I can say from the information provided is that you are doing something wrong in your calculation. Because MEDIAN and MEDIANX work for your data. See attached PBIX.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.