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
rdnguyen
Helper V
Helper V

Count distinct with priority

Hi everyone,

I have a list of items that I did count for late delivery and on time delivery. It means the item could be in both category Late and On-time. By doing the count for each category, I realized the total was over calculated. For example, I counted Item A has 1 "late", 2 "on-time", but would be considered "late" in overall.

 

How could I add this filter condition while counting on-time for not including this item?

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @rdnguyen ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1673848712406.png

Please try:

Late = 
var _a = SUMMARIZE('Table',[ID],"Flag",IF("Late" in SELECTCOLUMNS(FILTER(ALL('Table'),[ID]=EARLIER('Table'[ID])),"Category",[Category]),"Late","On-Time"))
return COUNTX(FILTER(_a,[Flag]="Late"),[Flag])

On-Time = 
var _a = SUMMARIZE('Table',[ID],"Flag",IF("Late" in SELECTCOLUMNS(FILTER(ALL('Table'),[ID]=EARLIER('Table'[ID])),"Category",[Category]),"Late","On-Time"))
return COUNTX(FILTER(_a,[Flag]="On-Time"),[Flag])

Final output:

vjianbolimsft_1-1673849218565.png

Best Regards,

Jianbo Li

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

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @rdnguyen ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1673848712406.png

Please try:

Late = 
var _a = SUMMARIZE('Table',[ID],"Flag",IF("Late" in SELECTCOLUMNS(FILTER(ALL('Table'),[ID]=EARLIER('Table'[ID])),"Category",[Category]),"Late","On-Time"))
return COUNTX(FILTER(_a,[Flag]="Late"),[Flag])

On-Time = 
var _a = SUMMARIZE('Table',[ID],"Flag",IF("Late" in SELECTCOLUMNS(FILTER(ALL('Table'),[ID]=EARLIER('Table'[ID])),"Category",[Category]),"Late","On-Time"))
return COUNTX(FILTER(_a,[Flag]="On-Time"),[Flag])

Final output:

vjianbolimsft_1-1673849218565.png

Best Regards,

Jianbo Li

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

Thanks @v-jianboli-msft , work great!

tamerj1
Super User
Super User

Hi @rdnguyen 

you need to iterate over "items" like

SUMX (

VALUES ( 'Table'[Item Name] ),

[Count Measure] 

)

Anonymous
Not applicable

hello @rdnguyen can you please provide with more detail or sample?

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.