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
TallKewlOnez
Helper I
Helper I

Inner Join with custom conditions

I need to reproduce an MSSQL Join in PowerBI, please help (yes I am new)

 

SELECT [dbo].[Table2].[sID],
[dbo].[Table1].[rVer]
FROM [dbo].[Table1]
JOIN [dbo].[Table2] ON [dbo].[Table2].[sName] = (REPLACE([dbo].[Table1].[objImpact], 'per_', ''));

 

Any assistance would be appreciated.

1 ACCEPTED SOLUTION

@Anonymous solution is ok but don't merge in power query, just load both the tables and set relationship between the tables on the columns you are using for join in SQL, but yes, do the replacement in Power Query

 

Merge is an expensive query and if not required, one should avoid it.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

7 REPLIES 7
fhill
Resident Rockstar
Resident Rockstar

There's probably a more technial way to do this, but to keep it simeple (Since Manage Relationships in Power BI Desktop doesn't have 'code' behind it) I created a New Column  in Table1 and used SUBSTITUTE to remove any "per_" and replace with blank.   Then I can link the new column to SName to create the relationship.

Forrest

 

 

** My picture isn't showing up... here's the code I used...**

New Table = SUBSTITUDE(Table1[objImpact], "per_","")




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




fhill
Resident Rockstar
Resident Rockstar

Capture.PNG




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Anonymous
Not applicable

You will need to use power query to accomplish this. You will need to do the following -

1) Import both tables into power query

2) Perform any the "Replace" Transform on table 1.

3) use the "Merge" function in power query to join the tables.

@Anonymous solution is ok but don't merge in power query, just load both the tables and set relationship between the tables on the columns you are using for join in SQL, but yes, do the replacement in Power Query

 

Merge is an expensive query and if not required, one should avoid it.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks very much

Anonymous
Not applicable

Agreed merge should be avoided. Relating tables is preferred but maybe a bit unintuitive.

collinq
Super User
Super User

Hi TallKewlOnez,

 

Power BI syntax is a bit different than SQL syntax and I am going to answer the question as asked but I am wondering if you should be doing this by using this method at all.  It appears to me that you are just "moving SQL to Power BI" when it might be more efficient to use Power BI to import the tables and link them in the Manage Relationships.  This will probably give you more flexibility and less need to rely on the SQL.

 

That said, if you are trying to for a SQL statement something like this should work (to be honest, I am not positive about the "replace" part but you can probably experiment a bit to get that right:

SELECT Table2.sID, Table1.rVer
FROM Table1
LEFT JOIN Table2 ON Table2.sName = (REPLACE(Table1.objImpact, 'per_', ''))




Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!
Private message me for consulting or training needs.




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.