Forum Discussion

rh128's avatar
rh128
Frequent Visitor
3 years ago

Need help on IF DAX query

I'm not sure if I need an IF query here or not, but I'm trying go up a management chain to find the manager of a user with 'VP' or 'Vice President' in their job title. All data is on the same table.

 

So I can do a lookupvalue, or calculate, and pull the title back for the manager based on unique fields. Every user has a unique UserName, and unique ID.  So in the below table example, I can lookup a user's ManagerID and match to ID to get their title. All of that makes sense.

 

However, that manger may not have VP or Vice President in their title, and I would need to go up to the next manager of the current manager, just going up the chain until the title contains VP or Vice President. I'm open to any methods of doing this and am happy to provide more data if required. Appreciate all help in advance!

 

Table:

UserNameIDManagerIDTitle

3 Replies

  • rh128's avatar
    rh128
    Frequent Visitor

    I've managed to get everything on to a single table. Here is a bit better of a mock up with sample data and my terrible logic of how it could be done. Hopefully this clears the situation up. There is no set standard location of VP/Vice President in the chain either.

    I did try using the child-parent hierarchy, and can see the lenght, but am unable to extract only the value that contains a specific title.

     

     

    UN                  EmpID SupervisorEmpId  SupervisorUN  JobTitle          VP  
    aa123111222bb123SPMdd123
    bb123222333cc123LPMdd123
    cc123333444dd123DIRdd123
    dd123444555ee123Vice Presidentdd123
    ee123555  Owner 

     

    Starting with Row 1 (First user)

    VP =
    VAR CUN = aa123
    VAR CJT = SPM
    VAR NextLeader = bb123
    VAR NextLeaderTitle = LPM

    RETURN

    IF(CONTAINSSTRING(CJT,"VP" OR "Vice President", ap[EmpID],
    IF(CONTAINSSTRING(NextLeaderTItle,"VP" OR "Vice President"),NextLeader,

    -- In this case, the "NextLeaderTitle" is LPM, so we would need to loop again and look at the next leader which is UN(User name) cc123 :
    LOOKUPVALUE(ap[SupervisorUN],ap[UN],NextLeader)

    Then we must get this leader title (Job Title for cc123). If it does NOT contain VP/Vice President, then we loop again using this UN  and get the leader which is dd123.

    Check to see if dd123's title contains VP/Vice President, which it does. So our output would be dd123. This is where the loop should complete.