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

One-to-many relationship and calculated columns

Hi everyone,

 

I have two tables with relationship "one-to-many" linked by column "ID" where:
- Table1 has unique ID values
- Table2 has a subset of those ID, but potentially repeated multiple times (up to 3). Table2 also have a column "Cat" that if filtered by Cat = "A" makes the list of ID in Table2 unique again (teoretically the relationship comes back to a "one-to-one" with Table1).

 

Question is: how can I set up a DAX code for a calculated column in Table1 that returns "YES" if Table2 has an entry for that ID and has Cat="A" and "NO" if there is no ID in Table2 or if there is the ID but with Cat<>"A"?

As of now I have a Table3 that has unique IDs and multiple columns for the different "Cat" to have the one-to-one relationship and the RELATED function working, but I'd like to get rid of this duplication.

Thanks!

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous ,

A new column in Table 1

if(isblank(countx(filter(table2,table1[ID] = table2[ID] and table2[Cat] ="A"),table2[Cat])),"No","Yes")

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

az38
Community Champion
Community Champion

@Anonymous 

the same but with EARLIER()

 

Column= 
var _count = CALCULATE(COUNTROWS(Table2), FILTER(ALL(Table2), Table2[ID] = EARLIER(Table1[ID]) && Table2[Cat] = "A") )
RETURN
IF(_count > 0, "YES", "NO")

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Thank you both gents, both solutions are working fine!
@amitchandak  @az38 

amitchandak
Super User
Super User

@Anonymous ,

A new column in Table 1

if(isblank(countx(filter(table2,table1[ID] = table2[ID] and table2[Cat] ="A"),table2[Cat])),"No","Yes")

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

Hi @Anonymous 

 

you can create a measure

Measure = 
var _count = CALCULATE(COUNTROWS(Table2), FILTER(ALL(Table2), Table2[ID] = SELECTEDVALUE(Table1[ID] && Table2[Cat] = "A") )
RETURN
IF(_count > 0, "YES", "NO")

and I don't understand why do you need third table. I'm sure there could be more appropriate solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

@az38 thanks for the hint.
That is for a measure, but I am trying to find a way to create a calculated column in Table1 as I would like to use this also as a slicer/category in charts and not only as a measure

az38
Community Champion
Community Champion

@giogiogio

the same but with EARLIER()

Column= 
var _count = CALCULATE(COUNTROWS(Table2), FILTER(ALL(Table2), Table2[ID] = EARLIER(Table1[ID]) && Table2[Cat] = "A") )
RETURN
IF(_count > 0, "YES", "NO")


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
az38
Community Champion
Community Champion

@Anonymous 

the same but with EARLIER()

 

Column= 
var _count = CALCULATE(COUNTROWS(Table2), FILTER(ALL(Table2), Table2[ID] = EARLIER(Table1[ID]) && Table2[Cat] = "A") )
RETURN
IF(_count > 0, "YES", "NO")

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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
Top Kudoed Authors