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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
minaxi
Frequent Visitor

Look up values from two different table basis filter conditions

Hi,

 

I need to build a report where values in the table is the lookup values from another table.

Lets say I have 4 different table: Campaign, Campaign Member, Contact and Lead.

Campaign Table  
Campaign IDCampaign NameCampaign Member ID
123abc12345
123abc1234567
345def345
57ghk222
12kfjd566

 

 

Campaign Member Table      
campaign Member IDTypeLead IDContactID   
12345Lead1800 null   
1234567Lead1900 null   
345Contactnull2000   
222Contactnull1234   
566Contactnull8900   

 

Lead Table

LeadIDFirst NameLastNameEmail
1800johnvjohnv@abc.com
1900marryJoshephmarryj@yahoo.com

 

Contact Table

ContactIDLastNameLastNameEmail
2000AmitKumarkumarA@get.com
1234NeilAmneil123@microsoft.com
8900VikashSinghvikashsingh11@info.com

 

I want to create a report with following fields.

 

Campaign IDCampaign NameCampaign Member IDTypeLead/ContactIDFirst NameLastName

So FirstName, LastName values should come from Lead table when Type is Lead and if Type is Contact, Firstname and LastName values will looked up from Contact Table.

How this can be implemented?

2 ACCEPTED SOLUTIONS
PattemManohar
Community Champion
Community Champion

@minaxi Please try below steps:

 

Step 1 : Add a calculated column in CampaignMember Table as below

 

 

LeadContactID = IF(Test70CampaignMember[Lead ID]=BLANK(),Test70CampaignMember[ContactID],Test70CampaignMember[Lead ID] )

 

It will be now as below:

 

image.png

 

 

Step 2 : Merge both Lead and Contact table using either Power Query or DAX. In this case, I've used DAX to create a new table as below

 

Test70LeadContact = UNION(Test70Lead,Test70Contact) 

Note - I've renamed the first field as ID (to be generic)

 

 image.png

 

Step 3: Please check and ensure now the relationship looks as below:

 

image.png

 

That's it !! Now you simple drag the corresponding fields as required and the expected output will be as below

 

image.png





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

Proud to be a PBI Community Champion




View solution in original post

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @minaxi,

 

Establish a relationship between 'Campaign' and 'Campaign Member'. Create below measures:

Lead/ContactID =
IF (
    SELECTEDVALUE ( 'Campaign Member'[Type] ) = "Lead",
    SELECTEDVALUE ( 'Campaign Member'[Lead ID] ),
    SELECTEDVALUE ( 'Campaign Member'[ContactID] )
)

First Name =
IF (
    SELECTEDVALUE ( 'Campaign Member'[Type] ) = "Lead",
    CALCULATE (
        SELECTEDVALUE ( 'Lead'[First Name] ),
        FILTER ( 'Lead', 'Lead'[LeadID] = [Lead/ContactID] )
    ),
    CALCULATE (
        SELECTEDVALUE ( 'Contact'[FirstName] ),
        FILTER ( 'Contact', 'Contact'[ContactID] = [Lead/ContactID] )
    )
)

Last Name =
IF (
    SELECTEDVALUE ( 'Campaign Member'[Type] ) = "Lead",
    CALCULATE (
        SELECTEDVALUE ( 'Lead'[LastName] ),
        FILTER ( 'Lead', 'Lead'[LeadID] = [Lead/ContactID] )
    ),
    CALCULATE (
        SELECTEDVALUE ( 'Contact'[LastName] ),
        FILTER ( 'Contact', 'Contact'[ContactID] = [Lead/ContactID] )
    )
)

Add corresponding fields and above measures into a Table visual.

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @minaxi,

 

Establish a relationship between 'Campaign' and 'Campaign Member'. Create below measures:

Lead/ContactID =
IF (
    SELECTEDVALUE ( 'Campaign Member'[Type] ) = "Lead",
    SELECTEDVALUE ( 'Campaign Member'[Lead ID] ),
    SELECTEDVALUE ( 'Campaign Member'[ContactID] )
)

First Name =
IF (
    SELECTEDVALUE ( 'Campaign Member'[Type] ) = "Lead",
    CALCULATE (
        SELECTEDVALUE ( 'Lead'[First Name] ),
        FILTER ( 'Lead', 'Lead'[LeadID] = [Lead/ContactID] )
    ),
    CALCULATE (
        SELECTEDVALUE ( 'Contact'[FirstName] ),
        FILTER ( 'Contact', 'Contact'[ContactID] = [Lead/ContactID] )
    )
)

Last Name =
IF (
    SELECTEDVALUE ( 'Campaign Member'[Type] ) = "Lead",
    CALCULATE (
        SELECTEDVALUE ( 'Lead'[LastName] ),
        FILTER ( 'Lead', 'Lead'[LeadID] = [Lead/ContactID] )
    ),
    CALCULATE (
        SELECTEDVALUE ( 'Contact'[LastName] ),
        FILTER ( 'Contact', 'Contact'[ContactID] = [Lead/ContactID] )
    )
)

Add corresponding fields and above measures into a Table visual.

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PattemManohar
Community Champion
Community Champion

@minaxi Please try below steps:

 

Step 1 : Add a calculated column in CampaignMember Table as below

 

 

LeadContactID = IF(Test70CampaignMember[Lead ID]=BLANK(),Test70CampaignMember[ContactID],Test70CampaignMember[Lead ID] )

 

It will be now as below:

 

image.png

 

 

Step 2 : Merge both Lead and Contact table using either Power Query or DAX. In this case, I've used DAX to create a new table as below

 

Test70LeadContact = UNION(Test70Lead,Test70Contact) 

Note - I've renamed the first field as ID (to be generic)

 

 image.png

 

Step 3: Please check and ensure now the relationship looks as below:

 

image.png

 

That's it !! Now you simple drag the corresponding fields as required and the expected output will be as below

 

image.png





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

Proud to be a PBI Community Champion




@PattemManohar

 

It worked for me. Thanks for your quick reply. 🙂

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors