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
ClemFandango
Advocate II
Advocate II

Populate column based on value in another column using DAX

Hi all,

 

I am trying to create a calculated column that returns “yes” where any ‘Ref’ value has one or more values in ‘Code’. The data table looks like below and both ‘Ref’ and ‘Code’ are text columns. I am trying to recreate ‘RefHasCode?’ as a new column in DAX that returns either “Yes” or blank based on conditions in both 'Ref' & 'Code'.

 

Any ideas greatly appreciated!

 

Table1

Ref     Code     RefHasCode?
1233Yes
134Yes
2  
3 Yes
312Yes
1 Yes
2 ACCEPTED SOLUTIONS
Bmejia
Super User
Super User

Add this column to your table

RefHasCode? =
 VAR CountCode = CALCULATE(COUNT('Table1'[Code]),ALLEXCEPT('Table1','Table1)'[Ref]))
 RETURN
If(CountCode>=1,"Yes"," ")
 
Note that when i pasted your data into my data sample the blanks were being counted, so i cleaned the records on my table by replacing the blanks with "null" during the data transformation.  You might not run into this issue but just in case you do replace your blank values in the Code column to null.
Bmejia_0-1713563786714.png

 


View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

Column = if(CALCULATE(COUNTa(Data[Code]),FILTER(Data,Data[Ref]=EARLIER(Data[Ref])&&Data[Code]<>BLANK()))>0,"Yes",BLANK())

Hope this helps.

Ashish_Mathur_0-1713581888967.png

 


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

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

Column = if(CALCULATE(COUNTa(Data[Code]),FILTER(Data,Data[Ref]=EARLIER(Data[Ref])&&Data[Code]<>BLANK()))>0,"Yes",BLANK())

Hope this helps.

Ashish_Mathur_0-1713581888967.png

 


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

 

Huge thanks @Ashish_Mathur  & @Bmejia !

 

Both of your suggestions worked wonderfully!

You are welcome.


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

Add this column to your table

RefHasCode? =
 VAR CountCode = CALCULATE(COUNT('Table1'[Code]),ALLEXCEPT('Table1','Table1)'[Ref]))
 RETURN
If(CountCode>=1,"Yes"," ")
 
Note that when i pasted your data into my data sample the blanks were being counted, so i cleaned the records on my table by replacing the blanks with "null" during the data transformation.  You might not run into this issue but just in case you do replace your blank values in the Code column to null.
Bmejia_0-1713563786714.png

 


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