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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
elsacq
Regular Visitor

count rows per product with filters

Hi! 

I need to create a measure to count when status is KO how many OKs are after the KO startdate.

 

Sample of data

IdIdProductStatusStartdate
13568KO1/8/23 9:00
23568OK1/8/23 10:00
33999KO1/8/23 10:30
43568OK1/8/23 12:00

 

What I need:

IdProduct#postOK
35682
39990

 

I tried:

PostOK =
VAR currentdate = SELECTEDVALUE(facttable[startdate])
VAR currentproduct = SELECTEDVALUE(facttable[idproduct])
RETURN
CALCULATE(
    DISTINCTCOUNT(facctable[id]),
    FILTER(
        ALLSELECTED(facttable),
        facttable[IdProduct]=currentproduct && facctable[startdate]>currentdate),
    status[status]="OK")
 
If I don't filter by status the result is:
IdIdProduct#postOK
135682
235681
 
but when I filter my table to see only KO rows, the postOK measure is blank.
 

Any help will be appreciated.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @elsacq ,

 

According to your description, here are my steps you can follow as a solution.

(1)My test data is the same as yours.

(2) We can create a measure. 

PostOK = 
var _date=CALCULATE(MAX('facttable'[Startdate]),FILTER(ALL('facttable'),'facttable'[IdProduct]=MAX('facttable'[IdProduct]) && 'facttable'[Status]="KO"))
var _count= COUNTROWS(FILTER(ALL('facttable'),'facttable'[IdProduct]=MAX('facttable'[IdProduct]) && 'facttable'[Startdate] > _date && 'facttable'[Status]="OK"))
return IF(_count = BLANK() ,0, _count)

(3) Then the result is as follows.

vtangjiemsft_0-1691043379090.png

Best Regards,

Neeko Tang

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

View solution in original post

2 REPLIES 2
elsacq
Regular Visitor

thanks a lot! I've been struggling with this for days

Anonymous
Not applicable

Hi @elsacq ,

 

According to your description, here are my steps you can follow as a solution.

(1)My test data is the same as yours.

(2) We can create a measure. 

PostOK = 
var _date=CALCULATE(MAX('facttable'[Startdate]),FILTER(ALL('facttable'),'facttable'[IdProduct]=MAX('facttable'[IdProduct]) && 'facttable'[Status]="KO"))
var _count= COUNTROWS(FILTER(ALL('facttable'),'facttable'[IdProduct]=MAX('facttable'[IdProduct]) && 'facttable'[Startdate] > _date && 'facttable'[Status]="OK"))
return IF(_count = BLANK() ,0, _count)

(3) Then the result is as follows.

vtangjiemsft_0-1691043379090.png

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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