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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ClemFandango
Helper II
Helper 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
Solution Supplier
Solution Supplier

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
Solution Supplier
Solution Supplier

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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