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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Lookup values from multiple tables

Hi,

 

I have the below Structure where "Table 3" is the main table connected to other 3 sources with details. I'd like to create a formula (calculated column) that will lookup the "Code" value from each detail table by a specific lookup prioritization.

Ex. The search columns will be "Count" and "Order" from Table 3 and the result Column will be "Code" from any of the 3 detail tables.
First it will look for Count value in Table 1, if it finds the value, then it takes the value from column "Code" in Table 1, if the Count value is not found, then it goes to Table 2, if that is not found, then it looks for "Order" value in Table 4 and takes as a response the value from colum "Code" in Table 4.

Exce1.png

  The expected output will be :
Exce.png

 

Appreciate all suggestions.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Greg_Deckler Thanks for your suggestion. However, the full data model is pretty big and I'd like to avoid any bi-directional relationships. I was thinking of a formula like :

Lookup Column = SWITCH(
TRUE(),
LOOKUPVALUE(Table1[Code],Tabel1[Count],Tabel3[Count])>1,LOOKUPVALUE(Table1[Code],Tabel1[Count],Tabel3[Count]),
LOOKUPVALUE(Table2[Code],Tabel2[Count],Tabel3[Count])>1,LOOKUPVALUE(Table2[Code],Tabel2[Count],Tabel3[Count]),
LOOKUPVALUE(Table4[Code],Tabel4[Order],Tabel3[Order])>1,LOOKUPVALUE(Table4[Code],Tabel4[Order],Tabel3[Order]),
BLANK()
)
 
 It seems that it works fine, but I'm not sure if I'm taking into account all possible implications....

For your testing:

Table1
CountCode
11234
21235
31236

 

Table 2

CountCodeDate
212379/11/2020
512389/12/2020
612399/13/2020

Table 3
OrderCountusernameGender
12432AAM
24433ABF
35434ACM


Table 4
OrderCodeDatestatus
112399/13/2020Completed
212409/15/2020Completed
412419/16/2020Completed
Thanks.

View solution in original post

6 REPLIES 6
mohammadyousaf
Resolver II
Resolver II

can someone please help to change the above dax to use with text instead of strings.? I am getting the following error:
Function 'SWITCH' does not support comparing values of type True/False with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

Thank you in advance. 

Greg_Deckler
Super User
Super User

@Anonymous - To ammend this, maybe try changing your relationship direction to both on Table1 and Table3? So, thinking in your Table:

 

Table3[OrderID]

Table3[Count]

Table1[Code]

 

This should work without any calculations if you change that relationship direction to Both

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler Thanks for your suggestion. However, the full data model is pretty big and I'd like to avoid any bi-directional relationships. I was thinking of a formula like :

Lookup Column = SWITCH(
TRUE(),
LOOKUPVALUE(Table1[Code],Tabel1[Count],Tabel3[Count])>1,LOOKUPVALUE(Table1[Code],Tabel1[Count],Tabel3[Count]),
LOOKUPVALUE(Table2[Code],Tabel2[Count],Tabel3[Count])>1,LOOKUPVALUE(Table2[Code],Tabel2[Count],Tabel3[Count]),
LOOKUPVALUE(Table4[Code],Tabel4[Order],Tabel3[Order])>1,LOOKUPVALUE(Table4[Code],Tabel4[Order],Tabel3[Order]),
BLANK()
)
 
 It seems that it works fine, but I'm not sure if I'm taking into account all possible implications....

For your testing:

Table1
CountCode
11234
21235
31236

 

Table 2

CountCodeDate
212379/11/2020
512389/12/2020
612399/13/2020

Table 3
OrderCountusernameGender
12432AAM
24433ABF
35434ACM


Table 4
OrderCodeDatestatus
112399/13/2020Completed
212409/15/2020Completed
412419/16/2020Completed
Thanks.

@Anonymous You could use LOOKUPVALUE. How are your Table1 and Table3 related? What columns? And is it 

 

Table1  1->*  Table3 

 

?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler  Table 1 is related to Table 3 as One to Many by Count columns. Thanks.

Greg_Deckler
Super User
Super User

@Anonymous Can you post that sample data as text? That way I can create a model and test. I realize that there isn't a ton of data to type in but makes it way easier.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.