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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Join one table if condition is met and another table if another condition is met

Let's say I have the following tables:

Table 1:

Order IDgroup 
11
22
31
42
5

2

 

Table 2:

order IDname group 1
1a
3b

 

Table 3:

order IDname group 2
2c
4d
5e

 

I want to join table 1 to either table 2 or 3 based on condition. If group = 1 then bring name column from table 2, if group = 2, bring name column from table 3. How would I do that?

 

Thanks

 

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @Anonymous 

 

Try this code to add a new column :

Name Group = 
Var _A = LOOKUPVALUE('Table 2'[name group 1],'Table 2'[order ID],'Table 1'[Order ID])
Var _B = LOOKUPVALUE('Table 3'[name group 2],'Table 3'[order ID],'Table 1'[Order ID])
return
if('Table 1'[group ]=1,_A,_B)

 

output:

VahidDM_0-1645137602527.png

 

 

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

2 REPLIES 2
VahidDM
Super User
Super User

Hi @Anonymous 

 

Try this code to add a new column :

Name Group = 
Var _A = LOOKUPVALUE('Table 2'[name group 1],'Table 2'[order ID],'Table 1'[Order ID])
Var _B = LOOKUPVALUE('Table 3'[name group 2],'Table 3'[order ID],'Table 1'[Order ID])
return
if('Table 1'[group ]=1,_A,_B)

 

output:

VahidDM_0-1645137602527.png

 

 

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

AlexisOlson
Super User
Super User

Add a group column to Table 2 and Table 3 and then append them together to get

AlexisOlson_0-1645137031254.png

Then you can merge the appended table with Table 1.

AlexisOlson_1-1645137092209.png

Finally, expand the name column.

AlexisOlson_2-1645137158892.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.