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
Anonymous
Not applicable

Count rows by column that contains more values in other column

Hello, 

 

I have a specific case here that I cannot move on and I have read through a few of forums.

I have a table of users with groups. Every user can have more groups - so 1 user is on more rows.

I need to count rows by users if in group column exist 2 special groups (group1 and group2).

See example below: user A has group1 and group2 - I want this user into selection

user B has only group1 - I do not want this user into selection

user C has only group2 - I do not want this user into selection

 

Screenshot 2021-10-06 150721.jpg

 

So I created the measure:

Special_Group =
VAR Group1Count=
CALCULATE(
COUNT('user groups'[User Account ID]),
FILTER(
'user groups',
SEARCH("Group1",'user groups'[GroupName],,blank())>0
)
)

VAR Group2Count=
CALCULATE(
COUNT('user groups'[User Account ID]),
FILTER(
'user groups',
SEARCH("Group2",'user groups'[GroupName],,blank())>0
)
)
RETURN
IF((IF(Group1Count>=1,1,0)+IF(Group2Count>=1,1,0))>=2,1,0)

 

easily - IF sum of Group1Count + Group2Count >=2 then 1 else 0

 

So I have now in powerbi  table:

User Account ID | Special Group

A | 1

B | 0

C | 0

 

but I need to COUNT these Users together - how many users with SpecialGroup I have - and I cannot SUM or COUNT the SpecialGroup. It says Total 1 - even if there is 100 users. I cannot use the measure in Legend also.

 

I wanted to add this measure as new Column - but I cannot do this also.

 

Could you please advise?

Thank you

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Create a new column like

 

 


new column =
var _1 = countx(filter(Table,[user] =earlier([user]) && [group] = "Group1"),[user])
var _2 = countx(filter(Table,[user] =earlier([user]) && [group] = "Group2"),[user])
return
if(not(isblank(_1)) && not(isblank(_2)),1,0)

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

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Create a new column like

 

 


new column =
var _1 = countx(filter(Table,[user] =earlier([user]) && [group] = "Group1"),[user])
var _2 = countx(filter(Table,[user] =earlier([user]) && [group] = "Group2"),[user])
return
if(not(isblank(_1)) && not(isblank(_2)),1,0)

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
Anonymous
Not applicable

Thank you very much for superquick and easy answer. I adapt your formula to this and this works like a charm!

 

new column =
var _1 = countx(filter(Table,[user] =earlier([user]) && SEARCH("Group1",[group] ,,blank())>0),[user])
var _2 = countx(filter(Table,[user] =earlier([user]) && SEARCH("Group2",[group],,blank())>0),[user])
return
if(not(isblank(_1)) && not(isblank(_2)),1,0)

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