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

How to count x2 distinct counts in 1 table (based on 2nd column criteria)

Hi 

Looking for some help.  I am new to Power BI and I am trying to create a KPI calculation of Faults per unit

 

I have a table that records all of the test results (Pass and Fail).

 

I am looking to count the number of fails per MO number, count the number of distinct MO number (Both of these I can get), however, I want to only count the Mo's that have faults and then calculate the number of MO's that had not faults

(I will then  divide the faults by Total units (qty Mo's with fault +  Mo's without faults)

 

See attached table

DateMO NumberPlant NumberFault Code
01/02/202310000Unit AInc Wiring
02/02/202310000Unit ALeak
03/02/202310001Unit BPass
03/02/202310002Unit CPass
04/02/202310004Unit DInc Wiring

 

So it should say = 2 NFF (Pass), 3 faults from 2 units (dont mind them being separate columns that I then perform a calculation on)

When calculated it should calc (3/(2+2)) =0.75

 

What is the DAX formula (formulae) to achieve this

 

1 ACCEPTED SOLUTION
andhiii079845
Super User
Super User

Try this:

andhiii079845_0-1677506540349.png

 

Ratio = 
VAR _CountFail = COUNTAX(FILTER('Table','Table'[Fault Code]<>"Pass"),'Table'[Plant Number])
VAR _CountMO = COUNTROWS(DISTINCT('Table'[MO Number]))
RETURN _CountFail/_CountMO




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

15 REPLIES 15
andhiii079845
Super User
Super User

You forget the define/copy the name: "Ratio =" 
Copy the whole defintion

Ratio = 
VAR _CountFail = COUNTAX(FILTER('Table','Table'[Fault Code]<>"Pass"),'Table'[Plant Number])
VAR _CountMO = COUNTROWS(DISTINCT('Table'[MO Number]))
RETURN _CountFail/_CountMO

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks - Resolved it.  Had copied the first line but it read ration no ratio (Must have copied it wrong)

Now working

 

Please mark my post as a solution if it suitable for you. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




done - but it only partially solves my issue.  I am still looking to see if someone can help me witht he 2nd part.

NOTE - there is a typo in your original solution - it says ration, instead of ratio.

Thank you. I corrected the typo. Do you try modify the measure for your own or what happened when you use it in the table with the product field? 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Diane_Gribi
Helper I
Helper I

Thanks I will try this. Love the idea of a single card presentation. Would the same formula work if I wanted to see this value for different products, could this data be presented in a table 

Product Name, Qty Faults, Qty units with Faults, Qty with No Faults, FPU

What would the formulas/measure look like to create and present these values

FPU is the ratio we discuss earlier?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Yes - but I was looking to see how I could split this by product and produce the columns above in a table (so that I can show the figures for analysis)

I currently have min of 3 product lines.  Can your ratio formula be filtered  using page or visual filtering 

Thanks for all of your support on this

 

Perhaps create a example how the table should look like with the new. measures and i can try later to change the measure in the right way for you. 

Please use the table function in this forum, so i do not have to copy the datas manually from a screenshot 🙂 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




DateInspectStageMOPlant NumberProductFault CodeWeek NumMonth QtrYear
01/01/01Test100111ABC100Product APass1JanQ101
02/01/01Test100112ABC101Product AInc Wiring1JanQ101
02/01/01Test100112ABC101Product AFluid Leak1JanQ101
02/01/01Test100113XYZ100Product BPass1JanQ101
02/01/01Test100114XYZ101Product BFluid Leak1JanQ101
02/01/01Test100114XYZ101Product BInc Wiring1JanQ101
08/01/01Test100115ABC102Product AFluid Leak2JanQ101
08/01/01Test100115ABC102Product AFluid Leak2JanQ101
09/01/01Test100116XZY102Product B

Pass

2JanQ101

 

Hi - Here is the table.  What I am looking to calculate is - 

By Week, Month, Qtr and Year

1) Qty of Fails (anything that does have pass in the fault code field)

2) Qty Units that have fails

3) Qty Unit with 0 faults (Any line that has pass in the fault code field)

4) FPU (No of fails/Total Qty Units (qty unit with fails + qty unit with 0 fails))

5) FPY (No of units with 0 fails/Total Qty Units (qty unit with fails + qty unit with 0 fails))

I have a reasonable handle on calculating 1, 2 (using the MO number with a distinct count) and 3.  But I am struggling to get it to calculate 4 and 5 as I cant get the DAX code or calculation to add a criteria into my distinct count to only count the MO's with a pass + MO's without stating pass

Any Suggestions on the item above?

 

You are welcome. Than please give a full data example. It will be possible to create a the requiered measures. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




DateMO NumberProductPlant NumberFault Code
01/02/202310000AABC001Inc Wiring
01/02/202310000AABC001Leak
01/02/202310001AABC002Pass
02/02/202310002BXYZ001Assy Fault
02/02/202310004BXYZ002Pass

Here is some data

 

andhiii079845
Super User
Super User

Try this:

andhiii079845_0-1677506540349.png

 

Ratio = 
VAR _CountFail = COUNTAX(FILTER('Table','Table'[Fault Code]<>"Pass"),'Table'[Plant Number])
VAR _CountMO = COUNTROWS(DISTINCT('Table'[MO Number]))
RETURN _CountFail/_CountMO




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi - Sorry, I copied the formula above but it is returned an error around the "return" syntax.  Any advice?

Diane_Gribi_0-1677507972272.png

 

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.