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...
  • PattemManohar's avatar
    7 years ago

    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
    7 years ago

    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