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
WayneC
Regular Visitor

Use reference table column as criteria in creating custom column in primary table

This may seem simple, I have been looking at several posts here on the forum, but cannot find a solution that I can even modify to fit my situation.

I have two tables.. The primary table is used for many things and is a rather large table.  the reference table is just that, holds a few names to reference.  When adding a custom column to my Primary table, I'd like to use the reference table as criteria.

TMI: I was able to use the reference table to filter the Primary, so I got that going for me.

 

here is the line of M:

= Table.AddColumn(#"Renamed Columns", "cc_Cristian", each if Text.Contains([foreman], "Cristian") then "Yes" else "No")

 

As you can see, "Cristian" is hard-wired. I'd rather like to use the below table to have the names and just reference them in this line:

WayneC_0-1685654261748.png

 

the final result would be 4 new columns (if I can do just 1, easy to rinse and repeat) with YES or NO, like this:

WayneC_1-1685653995017.png

 

Thanks,

Wayne

 

 

2 ACCEPTED SOLUTIONS
wdx223_Daniel
Super User
Super User

=Table.FromRecords(Table.TransformRows(#"Renamed Columns",each _&Record.FromTable(#table({"Name","Value"},List.Transform({"Cristian","Melvin","Adam","Mario"},(x)=>{"cc_"&x,if Text.Contains([foreman],x) then "Yes" else "No"})))))

View solution in original post

=Table.FromRecords(Table.TransformRows(#"Renamed Columns",each _&Record.FromTable(#table({"Name","Value"},List.Transform(ReferrenceTable[NameList],(x)=>{"cc_"&x,if Text.Contains([foreman],x) then "Yes" else "No"})))))

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

=Table.FromRecords(Table.TransformRows(#"Renamed Columns",each _&Record.FromTable(#table({"Name","Value"},List.Transform({"Cristian","Melvin","Adam","Mario"},(x)=>{"cc_"&x,if Text.Contains([foreman],x) then "Yes" else "No"})))))

Works as expected.  Is it possible to remove the hard coded names and use the name from the reference table (in the event the names change, would not want to have to search and replace them all).

WayneC_0-1685721648443.png

 

=Table.FromRecords(Table.TransformRows(#"Renamed Columns",each _&Record.FromTable(#table({"Name","Value"},List.Transform(ReferrenceTable[NameList],(x)=>{"cc_"&x,if Text.Contains([foreman],x) then "Yes" else "No"})))))

Works perfectly , thank you!

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.

Top Solution Authors
Top Kudoed Authors