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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Jerid421
Helper II
Helper II

Add Column Based on Whether Value Exists in Other Table

I have a query called Brand that I want to essentially LEFT OUTER JOIN  (if these were SQL tables) to another query called xrefKeyBrand to add one of it's columns (KeyBrandFlag).  The xrefKeyBrand is really just a list of all the "key" brands.  These two queries are joined on the Minor Brand Code field that exists in both queries.  I was able to write an M Query to "look up" the column in the related table, but it acts more like an INNER JOIN and reduces the resulting query's record count down to only what matches. I want all of the records in the Brand query and a new column that has a "1" if there is a matching Minor Brand Code record in the xrefKeyBrand query and a "0" if there isn't.   

Here is my query: 
= Table.AddColumn(#"Filtered Rows", "KeyBrandFlag",
(tblBrnd) => Table.First(
Table.SelectRows(xrefKeyBrand, each Text.StartsWith(tblBrnd[Minor Brand Code], [Minor Brand Code])) [KeyBrandFlag], Int64.Type)


Tables:

Brand.PNGxrefKeyBrand.PNG




 

1 ACCEPTED SOLUTION
Migasuke
Solution Sage
Solution Sage

Hi,

If I understand your problem correctly, the solution should be easy:
1. Create a Merged Table:

Migasuke_0-1625117383959.png

2. Use LEFT join (as you can see, only 3 records are matching out of 5)

Migasuke_1-1625117444055.png

3.In new Query, expand the second table and use your join column (in my case is Order ID)

Migasuke_2-1625117566188.pngMigasuke_3-1625117600651.png

4. Create a conditional column, where Order ID == OrderID.1

Migasuke_4-1625117669332.pngMigasuke_5-1625117710446.png


Let me know if this helps!



If my answer was helpful please give me a Kudos or even accept as a Solution.

Let's connect on LinkedIn!

View solution in original post

2 REPLIES 2
Jerid421
Helper II
Helper II

This isn't exactly how I accomplished it, but it did get me close enough to do what I was trying to do.     I used the merge query.  Just not as new query.  I didn't want a new query.   But thanks for the help!

Migasuke
Solution Sage
Solution Sage

Hi,

If I understand your problem correctly, the solution should be easy:
1. Create a Merged Table:

Migasuke_0-1625117383959.png

2. Use LEFT join (as you can see, only 3 records are matching out of 5)

Migasuke_1-1625117444055.png

3.In new Query, expand the second table and use your join column (in my case is Order ID)

Migasuke_2-1625117566188.pngMigasuke_3-1625117600651.png

4. Create a conditional column, where Order ID == OrderID.1

Migasuke_4-1625117669332.pngMigasuke_5-1625117710446.png


Let me know if this helps!



If my answer was helpful please give me a Kudos or even accept as a Solution.

Let's connect on LinkedIn!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors