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
TcT85
Helper III
Helper III

Distinct Count based on values and first date

I have a complicated calculation that needs to be visualised.

Here is an example of data.

 

Product Serial NumberTest IDStatusDate
A11111ID 888FAIL2023-01-11
A11111ID 888PASS2023-01-19
A22222ID 888PASS2023-01-19
A33333ID 888PASS2023-01-19
A44444ID 888PASS2023-01-19
A44444ID 888PASS2023-01-25
B55555ID 999FAIL2023-01-25
B55555ID 999PASS2023-01-26
B66666ID 999PASS2023-01-29
C77777ID 888PASS2023-02-01
C77777ID 999PASS2023-02-02
C77777ID 999PASS2023-02-20

 

  • From this data I need to distinct count the serial number over the dates
  • The same serial number cannot be recounted on multiple date.
  • The serial number should only be counted on column Status "PASS".

For example, serialnumber 11111 is shown on date 2023-01-11 with status "FAIL"  and 2023-01-19 with status PASS".

Result: The serial number has to be counted as 1 and on date 2023-01-19.

 

  • The serial number date has to defined by first date with status pass on the latest date TEST ID 

For example the serial number 77777 has ID888 with dates 2023-02-01, 2023-02-02 and ID999 with date 2023-02-20 and all status are PASS. 

Result: The serial number has to be counted as 1 over time and should be counted on date 2023-02-02

 

The pareto graph needs to result like this image:

TcT85_0-1681313025175.png

 

Another graph that i need will require Product on X-axis instead of Date.

Is this possible to do in Power BI?

 

 

 

 

9 REPLIES 9
TcT85
Helper III
Helper III

Hi Yolo Zhu,

 

I'm now trying with incremental refresh with transform data instead of direct query but with limited data.

But I'm still investigating if this incremental refresh with tranform data will actually work with big set of data.

 

Your suggestion works perfectly fine with incremental refresh with Transform data.

But I'm having issue with a follow up dax expression with your suggestion included.

[SerialNumber TestID Filter] is your suggestion in the DAX expression below.

 

TLOG Field Return PPM1 =
VAR FactoryCount = CALCULATE ( DISTINCTCOUNT( custClaimItem[intSerialNo] ), returnType[ReturnTypeTextEng] = "Field Return" )
VAR PCBSerialNrDist = SUM(TLOG_ProductionTest_view[SerialNumber TestID Filter])
VAR FactoryPPM = ((FactoryCount/PCBSerialNrDist)*1000000)
Return
IF(
    FactoryPPM = 0,
    BLANK(),
    FactoryPPM)

 

On 2023 jan 11 I get Infinity data, on 2023 jan 19 i get 1000000ppm which is correct.

How do I get rid of the Infinity data??

TcT85_1-1681904571717.png

 

v-xinruzhu-msft
Community Support
Community Support

Hi @TcT85 

You can refer to the following suggestion.

1.Create a calculated column in table

Flag = var a=FILTER('Table',[Serial Number]=EARLIER('Table'[Serial Number])&&[Status]="PASS")
var b=MINX(FILTER(a,[Test ID]=MAXX(a,[Test ID])),[Date])
return IF([Date]=b,1)

Then create a measure

Measure = SUM('Table'[Flag])

Put the measure to the visual

Output

vxinruzhumsft_0-1681441208323.png

 

vxinruzhumsft_1-1681441250855.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

 

I have tried your suggestion and it's working with Direct Query.

It worked when i created the example in Excel.

 

Do you have a workarround for DirectQuery?

Hi @TcT85 

You can try to create a calculated table

Table 2 = ADDCOLUMNS(ALL('Table'),"Flag",var a=FILTER('Table',[Serial Number]=EARLIER('Table'[Serial Number])&&[Status]="PASS")
var b=MINX(FILTER(a,[Test ID]=MAXX(a,[Test ID])),[Date])
return IF([Date]=b,1))

Then create the measure

Measure = CALCULATE(SUM('Table 2'[Flag]),FILTER('Table 2',[Date] in VALUES('Table'[Date])&&[Product ] in VALUES('Table'[Product ])))

vxinruzhumsft_0-1681802892693.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Yolo Zhu,

I get this error message when i try to create a calculated table.

 

Error Message:
The resultset of a query to external data source has exceeded the maximum allowed size of '1000000' rows.

 

 

 

TcT85_0-1681806286084.png

 

 I have to much data....

Hi @TcT85 

According to the error message, it can be seen that your data has exceeded the row limit, you can try the creation of calculated columns that I recommended at the beginning, and the Direct Query mode supports creating calculated columns

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Yolo Zhu,

 

I get 2 error message with the first suggestion.

 

2nd row

TcT85_0-1681811152188.png

1st row

TcT85_1-1681811290911.png

 

Hi @TcT85 

Try the following code

Calculated column

Flag = var a=FILTER('Table',[Serial Number]=EARLIER('Table'[Serial Number])&&[Status]="PASS")
var b=CALCULATE(LASTNONBLANK('Table'[Test ID],0),a)
var c=CALCULATE(FIRSTNONBLANK('Table'[Date],0),a,'Table'[Test ID]=b)
return IF([Date]=c,1)

Then create the measure,  the measure is the same as I have offered before.

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi Yolo Zhu,

Still getting error with DAX expressions on Direct Query.

TcT85_0-1681903627574.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.