Forum Discussion

minaxi's avatar
minaxi
Frequent Visitor
7 years ago
Solved

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
1800johnv[email protected]
1900marryJosheph[email protected]

 

Contact Table

ContactIDLastNameLastNameEmail
2000AmitKumar[email protected]
1234NeilAm[email protected]
8900VikashSingh[email protected]

 

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?

  • 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:

     

     

     

    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)

     

     

     

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

     

     

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

     

  • 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.

     

    Best regards,

    Yuliana Gu

3 Replies

  • PattemManohar's avatar
    PattemManohar
    Icon for Community Champion rankCommunity 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:

     

     

     

    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)

     

     

     

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

     

     

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

     

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Icon for Microsoft Employee rankMicrosoft 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.

     

    Best regards,

    Yuliana Gu