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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
mahenkj2
Solution Sage
Solution Sage

Need help on DAX code for Pass result based on measurement specification

Hi,

I am preparing a report for measurement data, one product is measured for several tests and each result is stored in a new row. So its a fact table. Another table is connected with it as one to many containing details on the tests done and specification, this is dimension table. I am trying to write two measures:

  1. calculating Pass/Fail for individual test for each product
  2. another measure to calculate If all such individual tests for a product are passed or not. So a final pass needs to be calculated.
Record IDProduct IDID_TestNameMeasurement ValueLower specUpper specResultFinal result
1A10.320.20.4PassFail
2A2131012501350PassFail
3A3200200 PassFail
4A45010PassFail
5A5335PassFail
6A611.4321112PassFail
7A7 1316FailFail
8B10.210.20.4PassPass
9B2129012501350PassPass
10B3190200 PassPass
11C10.31770.20.4PassFail
12C2132512501350PassFail
13C3225200 FailFail
14C45.4010PassFail
15C53.935PassFail
16C611.11112PassFail
17C714.71316PassFail

 

Above table is the fact table, I have brough the spec detail also here using measures and relationship. Now last two column needs to be written.

I have so far written:

Result = if(and(
AVERAGE('TestMeasurement'[Measured Value])>AVERAGE('SpecTable$'[Lower Spec]),
AVERAGE('TestMeasurement'[Measured Value])<AVERAGE('SpecTable'[UPPer Spec])),
"Pass","Fail")
I want to avoid Average/Sum in this formula, but I am not sure how that can be made possible. Second,
this does not calculate correct when test is not measured and spec is -ve to +ve e.g. -1 to 1, then consider
non meaured value as 0 and shows pass, but I would like to show here fail.
 
Second measure,
ResultPass = CALCULATE( COUNTROWS(FILTER('TestMeasurement','Measures'[Result]="Pass"))+0)
 
It does not work, I need to count all Pas value, so evaluation conext should perhaps remove the filter
on ID_TestName, but I am unable to do that.
 
Please advise and let me know if any questions.
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@mahenkj2 - For the second issue, that is a measures aggregation issue. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.

 

For the first issue, you cannot avoid the AVERAGE statements because you are doing this in a measure and measures require you to wrap column references in some aggregation like SUM, AVERAGE, MIN, MAX, etc. I'm not 100% clear on this requirement what you are going for. Please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@mahenkj2 , refer

 Measure 
 Result = if(and(
AVERAGE('TestMeasurement'[Measured Value])>AVERAGE('SpecTable$'[Lower Spec]),
AVERAGE('TestMeasurement'[Measured Value])<AVERAGE('SpecTable'[UPPer Spec])),
"Pass","Fail")

column 
 Result column = if(and(
'TestMeasurement'[Measured Value]>'SpecTable$'[Lower Spec],
'TestMeasurement'[Measured Value]<'SpecTable'[UPPer Spec]),
"Pass","Fail")


 Measure 
Final result  = maxx(summarize('TestMeasurement','TestMeasurement'[Product ID], "_1",count('TestMeasurement'[Recort ID]) ,  "_2" , countx('TestMeasurement', if(and(
'TestMeasurement'[Measured Value]>'SpecTable$'[Lower Spec],
'TestMeasurement'[Measured Value]<'SpecTable'[UPPer Spec]),
[Recort ID],blank()))),if([_1] =[_2] = "Pass","Fail"))


 Measure 
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Super User
Super User

@mahenkj2 - For the second issue, that is a measures aggregation issue. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.

 

For the first issue, you cannot avoid the AVERAGE statements because you are doing this in a measure and measures require you to wrap column references in some aggregation like SUM, AVERAGE, MIN, MAX, etc. I'm not 100% clear on this requirement what you are going for. Please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_DecklerThanks. After looking at your suggestion, I understood that Summarize should be the right function useful in my case, as you point in your linked post.

I could get access to this work with little delay and had to iterate several things then on, finally I managed well.

 

Just one request, your post points to a direction, and I saw people benefitted from that but I think you can improvise it with little mode detailing and pasting table image etc instead of writing relationships in text. For developer, this language may look no problem, but for newbies like me will struggle to go through it in one go.

 

Thanks.

@mahenkj2 - Glad you got it! Thanks for the suggestion!


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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