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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.