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

how to count rows with filter

Hi, 

 

I have a single PO with multiple order lines. 

Out of 3 lines, only 2 met on time delivery in full (OTIF). 

On purchase order level, this order does not meet the OTIF, zero

dogburalHK82_0-1684367976884.png

 

How can I calculate this using Dax?

I tried below but this gives me OTIF =1

 

OTIF Order level = calculate(DISTINCTCOUNT(Table[Purchase Order]),filter(Table, (Table[RECEIPT Date] <= Table[Performance Date] && Table[Backorder] = 0))
1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @dogburalHK82 

According to your description, you want to filter the OTIF by Purchase Order side.

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1684461321302.png

(2)We can create a measure like this:

Measure = var _t =  ADDCOLUMNS('Table',"flag" , IF([Promised Date]>[Receipt Date] ,0,1))
var _t2 = ADDCOLUMNS(_t , "flag2",var _order =[Purchase Order] var _sum=SUMX( FILTER(_t,[Purchase Order]=_order),[flag])  return IF(_sum>0 ,1,0))
var _end_table = FILTER(_t2 , [flag2]=0)
var _end_table2 = FILTER( SUMMARIZE(_end_table,'Table'[Purchase Order] , "backorder" , SUM([Backorder])) , [backorder]=0)
return
COUNTROWS(_end_table2)

Then we can meet your need , the result is as follows:

vyueyunzhmsft_1-1684461354288.png

 

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

1 REPLY 1
v-yueyunzh-msft
Community Support
Community Support

Hi , @dogburalHK82 

According to your description, you want to filter the OTIF by Purchase Order side.

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1684461321302.png

(2)We can create a measure like this:

Measure = var _t =  ADDCOLUMNS('Table',"flag" , IF([Promised Date]>[Receipt Date] ,0,1))
var _t2 = ADDCOLUMNS(_t , "flag2",var _order =[Purchase Order] var _sum=SUMX( FILTER(_t,[Purchase Order]=_order),[flag])  return IF(_sum>0 ,1,0))
var _end_table = FILTER(_t2 , [flag2]=0)
var _end_table2 = FILTER( SUMMARIZE(_end_table,'Table'[Purchase Order] , "backorder" , SUM([Backorder])) , [backorder]=0)
return
COUNTROWS(_end_table2)

Then we can meet your need , the result is as follows:

vyueyunzhmsft_1-1684461354288.png

 

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

 

 

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.