cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Naresh91
Microsoft
Microsoft

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
Community Champion
Community Champion

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 accept it as the solution to help other members find it faster, and give a big thumbs up.


Best regards, JiHwan Kim


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

Twitter: https://twitter.com/Jihwan_JHKIM

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors