cancel
Showing results for 
Search instead for 
Did you mean: 
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
Join Arun Ulag at MPPC23

Join Arun Ulag at MPPC23

Get a sneak peek into this year's Power Platform Conference Keynote.

PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Top Solution Authors
Top Kudoed Authors