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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Lookup on two tables and get value in the first table using different data types

Hi,

 

I am trying to use lookup function to get account values from two tables into the first table.

 

Table 1 is the master table and has two primary keys one text and one int, Table 2 is connected with text and table 3 with int to table 1.

 

I am trying to lookup on table 2 using text column to get the account value and if it is not present(blank) in table 2 then use table 3 using int as primary key to get the account value. I am using the below code.

 

The impact subtype and impact type are text columns and impact # is the integer.

 

</>

Account =
SWITCH(
TRUE(),
LOOKUPVALUE(Default[Account],Default[Impact SubType],impact[Impact type > Metric]),
LOOKUPVALUE(Exceptions[Account],Exceptions[Impact #],impact[impact #]),
BLANK()) </>
 
Can someone please help on how I can approach this.
3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Please share a sample. I might use two step approach At a time we can move data from one table to another

 


refer 4 ways to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

Anonymous
Not applicable

Hi @amitchandak ,

 

This is the main table

adityaaranya6_0-1634107450231.png

 

and it is getting data from two other tables with two primary keys

 

Table 2:

adityaaranya6_1-1634107500449.png

and Table 3

adityaaranya6_2-1634107531322.png

 

Table 2 and 3 have different primary key datastructure. 

If it is blank in table 2, the query should go to table 3 and fetch the corrosonding data and store it in the same column.

 

 

Hi @Anonymous,

I'd like to suggest you add an index field to 'table 3', then you can write a measure to use lookupvalue function and if statement to find corresponding values.

Add an index column | Microsoft Docs

Table visual design:

Index and Key_Str from 'table 3' as category, measure as value.

Measure =
VAR currIndex =
    MAX ( Table3[Index] )
VAR currAccount =
    LOOKUPVALUE ( Table3[Account], Table3[Index], currIndex )
VAR lookupAccount =
    LOOKUPVALUE ( Table2[Account], Table2[Key_int], currIndex )
RETURN
    IF ( currAccount <> BLANK (), currAccount, lookupAccount )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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