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
zoltansn
New Member

Create measure in Power BI to flag record based on condition in other, non-unique table

Hi all,

 

I have a table that is unique on ID, and another that is not. I need to create a measure to flag those IDs that appear in the other table with a condition. Let Friends be

IDName
1

Ben

2Jerry
3Ruth
4Lesley

 

Let FriendFamily be

IDFamilyMember
1kid*
1pet
1partner
2kid
2kid
2kid
3pet
4pet
4

partner

*human not goat

The tables are connected on ID (one to many). I would like a measure that flags each ID in Friends based on whether or not they have a pet. The tables are in a database, Direct Query is my only option (the real tables are massive). So far I've tried DISTINCTCOUNT in FriendFamily, with which I got to a point where I could have a table visual with 3 columns: ID, has_pet, has_human, but then I got lost in trying to figure out how to create calculations with this information. It wouldn't work as a filter for instance, when I tried to apply it to a card that showed distinct count on ID. The business requirements are:

  • how many distinct IDs are there with only pet family members?
  • how many distinct IDs are there with both pet and human family members?

The measures I've managed to build are below.

Has human family member = CALCULATE(DISTINCTCOUNT(FriendFamily[ID]),FriendFamily[FamilyMember] <> "pet")
Has pet family member = CALCULATE(DISTINCTCOUNT(FriendFamily[ID]),FriendFamily[FamilyMember] = "pet")
 
How do I get from these (or from scratch) to having flags in Friends like so (I don't need all these, just included various types, see, what's easiest and/or quickest to calculate):
IDName(measure)HasPet(measure)HasHuman(measure)HasBoth(measure)FamilyType
1Ben111Has Both
2Jerry010Only Human
3Ruth100Only Pet
4Lesley111Has Both
 
Thank you in advance!
1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Drag ID from the Friends table and drag this measure to the visual

Family members = if(DISTINCTCOUNT(FriendFamily[FamilyMember])=1,if(MAX(FriendFamily[FamilyMember])="kid","Only human","Only pet"),"Has Both")

Hope this helps.

Ashish_Mathur_0-1699661279486.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

1 REPLY 1
Ashish_Mathur
Super User
Super User

Hi,

Drag ID from the Friends table and drag this measure to the visual

Family members = if(DISTINCTCOUNT(FriendFamily[FamilyMember])=1,if(MAX(FriendFamily[FamilyMember])="kid","Only human","Only pet"),"Has Both")

Hope this helps.

Ashish_Mathur_0-1699661279486.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.