Forum Discussion

SBR1D's avatar
SBR1D
Helper III
2 years ago
Solved

Tricky calculated column lookup

Hi All

 

In the following example table I want to do a  calculated column to look up from the application table to employer table returning the Parent Employer.

name.

 

I've filled in what the outcome should be in the applications table in red text.

 

Thanks in advance.

 

 

Applications table     Employer table  
EmployerIDEmployer nameParent Employer Name   ParentIDEmployerIDEmployer name
11Employer AA1Employer AA1   1111Employer AA1
12Employer BB1Employer BB1   1212Employer BB1
13Employer CC1Employer CC1   1313Employer CC1
14Employer DD1Employer DD1   1414Employer DD1
15Employer AA2Employer AA1   1115Employer AA2
16Employer BB2Employer BB1   1216Employer BB2
17Employer CC2Employer CC1   1317Employer CC2
18Employer DD2Employer DD1   1418Employer DD2
  • There are PATH functions that can handle recursive hierarchy structures like I think your Employer table is intended to have. See here for details on that: https://www.daxpatterns.com/parent-child-hierarchies/

     

    For this, you can probably get away with two lookups like this:

    Parent Employer Name =
    VAR _ParentID =
        LOOKUPVALUE (
            Employer[ParentID],
            Employer[EmployerID], Applications[EmployerID]
        )
    VAR _ParentName =
        LOOKUPVALUE (
            Employer[Employer name],
            Employer[EmployerID], _ParentID
        )
    RETURN
        _ParentName

2 Replies

  • There are PATH functions that can handle recursive hierarchy structures like I think your Employer table is intended to have. See here for details on that: https://www.daxpatterns.com/parent-child-hierarchies/

     

    For this, you can probably get away with two lookups like this:

    Parent Employer Name =
    VAR _ParentID =
        LOOKUPVALUE (
            Employer[ParentID],
            Employer[EmployerID], Applications[EmployerID]
        )
    VAR _ParentName =
        LOOKUPVALUE (
            Employer[Employer name],
            Employer[EmployerID], _ParentID
        )
    RETURN
        _ParentName
  • Thank you so much. I will take a look into the link you have provided, I am not sure why the company chose to model the data like this as it is confusing. Unfortuanately, we use 3rd party software/databae so i am unable to change the model.

     

    But your solution works so thanks and have a great day.