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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register 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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.