Forum Discussion
New Column Creation
I want to create a new column based on the following logic:
this is how my dataset looks:
Id -> Emp Name's ID
Emp Name -> Employee Name
Mgr Name -> The Employees Manager
Apart from these 3 I have an additional column called Level (I was not sure how to put that as a column here for a mock dataset, so going to explain that in words)
So if Emp Name Law is the topmost, his direct reports say in this case Tra or Eri would be level 1. If you take Emp Name Meli, she is level 1 to her manager Tra, but her level = 2 for Law (Because Meli reports to Tra (Level 1) who reports to Law (Hence Level 2)
So I want to create a new column called Parent_ID based on the following logic:
Basically Parent ID is the manager's ID of the employee, but those ID's whose level =1 (The dataset already has these level numbers, so the DAX just needs this to be mentioned).
For example, You can see that Emp NameMeli (ID =4) reports to Mgr Tra (ID =2) So the Parent_ID column for Meli is 2 (Law would be a manager for her as well, but Law' ID does not become her Parent ID). But my dataset is so huge so I wanted to know if there is an easy way to do this. Similarly Emp Name Haz (ID=6) who reports to Tra also has Parent_ID =2
Another example would be Emp Name Chr (ID=7) reports to Haz(ID = 6) so Chr would have parent ID = 6.
Is there any way this can be done? The level part was just to describe how it works. But in my huge dataset i already have a level mapping with these managers. But I need the logic of the DAX for the new column to account for this such that they only get Parent_ID of their direct managers and not the indirect ones. Appreciate the help!
Anonymous ,
SelectEmpCombo = IF(EmpLevel[LEVEL]=1,LOOKUPVALUE(EmpLevel[EmpCombo],EmpLevel[Emp Name],EmpLevel[Mgr Name]))EmpCombo = CONCATENATE(EmpLevel[ID], CONCATENATE("," ,EmpLevel[Emp Name]))FindDelimiter = IF(EmpLevel[SelectEmpCombo]<> "",Find(",",EmpLevel[SelectEmpCombo]))ParentID = IF(EmpLevel[SelectEmpCombo]<>"",LEFT(EmpLevel[SelectEmpCombo],EmpLevel[FindDelimiter]-1))This should do it, although you may want to combine the columns. I left them separate for ease in debugging. First we combine the two columns [ID] and [Emp Name] into [EmpCombo] separated by ",". (This gives us a unique identifier for all. )Then we use IF() and LOOKUPVALUE () in [SelectEmpCombo. That gives us the answer, but then we need to separate out the Emp ID.
So, we use IF() and FIND() in [FindDelimiter] to find how many characters the ID is. Finally we use IF() and LEFT() to get the ParentID.
If this solves your issue, please consider marking it Solved. KUDOS are nice too!:smileyhappy:
15 Replies
- Nathaniel_CCommunity Champion
Hi Anonymous
Here is your original data table with a calculated column add [ParentID] The blanks are where we don't have data in the [Emp Name] column for the manager's name.
I had to copy the first two columns and create a second table (EMPID) in order to do the following DAX.
ParentID = LOOKUPVALUE(EmpID[ID],EmpID[Emp Name],Employee[Mgr Name])Think this matches the logic you described.Don't understand this (in red)"Basically Parent ID is the manager's ID of the employee, but those ID's whose level =1 (The dataset already has these level numbers, so the DAX just needs this to be mentioned). "If this answers your question, please consider marking this as the solution,- AnonymousNot applicable
Nathaniel_C Hey thank you for your respone.
The level example is as follows: If emp X reports directly to Mangager Y, then X's level for Y is level 1 (Because she directly reports).
Now this Manager Y itself is an employee who has manager Z. So Y's level 1 is person Z but X reports to Y who reports to Z so X is level two for Z. So in my table i have a column called Level that maps this number. But my parent ID is based on direct report only (Level 1). There should be a filter criteria in my DAX that says Level = 1.
Also all columns are from the same table
(For example:)
Emp Manager Level
X Y 1
Y Z 1
X Z 2
The bold column states that Z is a manager for X also but level 2. But i should get only y's id as parent_id not Z's for the employee X.
- Nathaniel_CCommunity Champion
Anonymous ,
Are you trying to create a calculated column to add to your table with dax?
Did my answer display how you would expect the ParentID to display?
I know we have some additional work to do with the new Level data that you described, but want to know if we are on the same page so far.
Thanks,
- v-diye-msftCommunity Support
Hi Anonymous ,
If above suggestion provided by Nathaniel_C does work, please kindly mark it as solution to help others find it more quickly. thanks!