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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
aledc
New Member

Count if based on two columns and ignoring another

ID            Category              Sub-category     Level
111         A                             !                              1

111         A                             ?                              1

111         B                             /                              1

111         B                             !                              1

111         C                             !                              2

111         C                             ?                              2

111         D                             !                              1

111         D                             ?                              1

222         A                             !                              2

222         B                             !                              1

222         B                             ?                              1

222         C                             !                              1

 

I want to create a column that tells you the distinct number of occurrences of ‘Level’ 1 for a given ‘ID’ based on the ‘Category’. For example, ID 111 has a level 1 for category A, B & D so I would want 3 in the new column. In essence, I want the sub-category to be ignored.

 

I’d want a table like this:

 

ID            Category              Sub-category     Level     Count of Level 1s
111         A                             !                              1              3                             

111         A                             ?                              1              3

111         B                             /                              1              3

111         B                             !                              1              3

111         C                             !                              2              3

111         C                             ?                              2              3

111         D                             !                              1              3

111         D                             ?                              1              3

222         A                             !                              2              2

222         B                             !                              1              2

222         B                             ?                              1              2

222         C                             !                              1              2

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @aledc ,

 

Try this:

Count of Level 1s =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Category] ),
    FILTER ( ALLEXCEPT ( 'Table', 'Table'[ID] ), 'Table'[Level] = 1 )
)

count.JPG

 

Best regards

Icey

 

If this post helps,then consider Accepting it as the solution to help other members find it faster.

View solution in original post

2 REPLIES 2
Icey
Community Support
Community Support

Hi @aledc ,

 

Try this:

Count of Level 1s =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Category] ),
    FILTER ( ALLEXCEPT ( 'Table', 'Table'[ID] ), 'Table'[Level] = 1 )
)

count.JPG

 

Best regards

Icey

 

If this post helps,then consider Accepting it as the solution to help other members find it faster.

amitchandak
Super User
Super User

@aledc , try measure like

 

calculate(distinctcount(Table[Category]), allexcept(Table, Table[ID]))

or

calculate(distinctcount(Table[Category]), filter(allselected(Table), Table[ID] =max(Table[ID])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors