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
Naresh91
Microsoft Employee
Microsoft Employee

How to count the Distinct count of ID's for each CategoryID whose status is s

Hi 

IDCategoryIDStatusFlagStatusDateOutput Count
a1231114/1/2021 
a1232114/1/20211
a1233114/1/20211
b2341014/3/2021 
b2342114/3/20211
a1231104/3/2021 
c1232 14/2/20211

 

from the above table need to count of ID for each  CategoryID whose status is either "blank" and "1" and FlagStatus is "1" for the Latest Date
"OutputCOunt" is the required output

Eg: for ID = "a123" have the 3 CategoryID's {1,2,3} from that Category ID's 2, 3 have the Flagstatus as 1 for latest Date but for CategoryID 1 have the FlagStatus as 0 for latest Date so it should not be counted.

 

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi, @Naresh91 

Please try the below measure.

 

Picture1.png

 

 

Output =
VAR currentcategory =
MAX ( 'Table'[CategoryID] )
VAR grouptablefindmaxdate =
MAXX (
GROUPBY (
FILTER ( ALL ( 'Table' ), 'Table'[CategoryID] = currentcategory ),
'Table'[CategoryID],
"@maxdate", MAXX ( CURRENTGROUP (), 'Table'[Date] )
),
[@maxdate]
)
VAR filtertable =
FILTER (
ALL ( 'Table' ),
'Table'[CategoryID] = currentcategory
&& 'Table'[Date] = grouptablefindmaxdate
&& 'Table'[Status] <> 0
&& 'Table'[FlagStatus] = 1
)
RETURN
COUNTROWS ( filtertable )

 

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Linkedin: https://www.linkedin.com/in/jihwankim1975/


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.