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

Z-Score Calculation with Multiple Filters

Hello,

I am rather new to Power BI and I am currently trying to use DAX codes to generate a Measure of Z-Scores with multiple filters.

The report is using Direct Query to a SQL database.

Here is an example of part of the table:
Test2 Table.PNG

I would like to categorize the Average Cycle Times (ACT) by Devices, and create a Measure that shows the Z-Scores of these ACTs based on averages and standard deviations for each Device.

However, I also want to ignore all the 0 entries in the ACT column.

Here is my DAX code for the Z-Scores without ignoring all the 0 entries:

ACT_Z = 
var mean = CALCULATE(AVERAGE('Test2'[ACT]),ALLEXCEPT('Test2','Test2'[Device]))
var deviation = CALCULATE(STDEV.P('Test2'[ACT]),ALLEXCEPT('Test2','Test2'[Device]))
return (SUM('Test2'[ACT])-mean)/deviation

And here is the result (I don't know if it is correct, but I think it is):

Test2 with Zero.PNG

And when I add the filter for ignoring the 0s:

ACT_Z = 
var mean = CALCULATE(AVERAGE('Test2'[ACT]),ALLEXCEPT('Test2','Test2'[Device]),FILTER('Test2','Test2'[ACT]>0))
var deviation = CALCULATE(STDEV.P('Test2'[ACT]),ALLEXCEPT('Test2','Test2'[Device]),FILTER('Test2','Test2'[ACT]>0))
return (SUM('Test2'[ACT])-mean)/deviation

Here is what I got:

Test2 no Zero.PNG

I can't figure out what the problem is, and if my previous DAX code was correct.

Would someone please take a look at it? I hope this is a quick fix. Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous - Please try to reconfigure like this and let us know whether it works:

ACT_Z = 
var mean = CALCULATE(
	AVERAGE('Test2'[ACT]),
	FILTER(
		ALLEXCEPT('Test2','Test2'[Device]),
		'Test2'[ACT]>0
	)
)
var deviation = CALCULATE(
	STDEV.P('Test2'[ACT]),
	FILTER(
		ALLEXCEPT('Test2','Test2'[Device]),
		'Test2'[ACT]>0
	)
)
return DIVIDE(
	SUM('Test2'[ACT])-mean,
	deviation
)

Hope this helps,

Nathan

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

hi @Anonymous 

Would agree with @Anonymous 

Your first part of dax z-score calculation is correct, but its better to do the filter on the first part itself without trying to call twice the code.

All the best

parry2k
Super User
Super User

@Anonymous assume you want to exclude zero entries in all the calculations

 

ACT_Z = 
var mean = CALCULATE(AVERAGE('Test2'[ACT]),ALLEXCEPT('Test2','Test2'[Device]),Test2'[ACT]>0)
var deviation = CALCULATE(STDEV.P('Test2'[ACT]),ALLEXCEPT('Test2','Test2'[Device]),Test2'[ACT]>0)

return (SUM('Test2'[ACT])-mean)/deviation


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@Anonymous - Please try to reconfigure like this and let us know whether it works:

ACT_Z = 
var mean = CALCULATE(
	AVERAGE('Test2'[ACT]),
	FILTER(
		ALLEXCEPT('Test2','Test2'[Device]),
		'Test2'[ACT]>0
	)
)
var deviation = CALCULATE(
	STDEV.P('Test2'[ACT]),
	FILTER(
		ALLEXCEPT('Test2','Test2'[Device]),
		'Test2'[ACT]>0
	)
)
return DIVIDE(
	SUM('Test2'[ACT])-mean,
	deviation
)

Hope this helps,

Nathan

 

Anonymous
Not applicable

Thank you, that worked perfectly.

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.