Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Rohitb
Helper I
Helper I

Creating derived columns via Power Query

Hello,

Below is my Source Table:

Employee IdDOJDOLIsContinuityNeededContinuedFor
17/28/20229/25/20231 
29/23/202311/30/20231 
310/2/2023   
45/30/20239/15/20231 
52/25/20239/10/2023  
612/15/2023  4
711/5/2023  2
812/6/2023   


I need to create 2 derived columns during data transformations (Power Query).

Below is the final Ouput State required.

 

Employee IdDOJDOLIsContinuityNeededContinuedForDOL_UpdatedDOJ_Updated
17/28/20229/25/20231 UTCNOW()7/28/2022
29/23/202311/30/20231 11/5/20239/23/2023
310/2/2023    10/2/2023
45/30/20239/15/20231 11/30/20235/30/2023
52/25/20239/10/2023  9/10/20232/25/2023
612/15/2023  4 12/15/2023
711/5/2023  2 12/01/2023
812/6/2023    12/6/2023

 

Here the requriment is :

Employees with No Departure Date (DOL):
For employees without a departure date (DOL),  the DOJ_Updated should be their actual joining date. (Example EmployeeID : 3 & 8 )

Employees with Departure Dates and No Continuity Requirement (IsContinuityNeeded is blank):
For employees with departure dates (DOL) and no continuity requirement (IsContinuityNeeded is blank), their DOJ_Updated & DOL_Updated should be same as the DOJ & DOL respecively. (Example EmployeeID : 5)

Employees with Departure Dates and Continuity Requirement (IsContinuityNeeded is 1):
a. If there's no replacement employee (ContinuedFor column is blank), the DOL_Updated should be the max data/utcnow/today.

DOJ_Updated should be same as DOJ. (Example EmployeeID : 1 )

b. If a replacement employee exists, and they joined before the departing employee (DOJ of replacement < DOL of departed),
the DOJ_Updated of the replacement employee should be the date after DOL Month end date of the departing employee.
For, the departing employee, DOJ_Updated & DOL_Updated remains same as DOJ & DOL respectively. 
(Example EmployeeID : 2/7 )

c. If a replacement employee exists, and they joined after the departing employee left (DOJ of replacement > DOL of departed), the DOJ_Updated for the replacement employee is their actual DOJ where as for the departing employee DOL_Updated is last day of the previous month of the DOJ of the replacement employee . (Example EmployeeID : 6/4 )


How can we acheive this ?

@amitchandak@lbendlin 

Thanks in advance.

6 REPLIES 6
NandanHegde
Super User
Super User

Not sure whether the below approach is a good one but you can try as below :

Create a duplicate table of the employee table.
Then below custom columns leveraging PositionOf and getting the value for that index :

DOJ_Updated :

if [ContinuedFor] = " " then [DOJ] else try Elookup[DOL]{ List.PositionOf( Elookup[EmloyeeId] , [ContinuedFor] ) } otherwise ""




DOL_Updated :
if [IsContinuityNeeded] <> 1 then [DOL] else if (try Elookup[DOJ]{ List.PositionOf( Elookup[ContinuedFor] , [EmloyeeId] ) } otherwise "") <>"" then (try Elookup[DOJ]{ List.PositionOf( Elookup[ContinuedFor] , [EmloyeeId] ) } otherwise "") else Date.EndOfMonth(DateTime.LocalNow())

@lbendlin :

Not sure whether this is good as duplicate table is being created. I am not aware of usage of PositionOf within the same tagble due to circular table dependency

 




----------------------------------------------------------------------------------------------
Nandan Hegde (MSFT Data MVP)
LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66
GitHUB Profile : https://github.com/NandanHegde15
Twitter Profile : @nandan_hegde15
MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942
Topmate : https://topmate.io/nandan_hegde
Blog :https://datasharkx.wordpress.com

Where did ELookup  come from?

Hey,

The ELookup is the name of the duplicate table of Employee




----------------------------------------------------------------------------------------------
Nandan Hegde (MSFT Data MVP)
LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66
GitHUB Profile : https://github.com/NandanHegde15
Twitter Profile : @nandan_hegde15
MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942
Topmate : https://topmate.io/nandan_hegde
Blog :https://datasharkx.wordpress.com
lbendlin
Super User
Super User

I already showed you a solution in your prior thread.

Hello @lbendlin 
Thankyou for your reply.

I was able to acheive the required output via DAX using the below query :

DOJ_Updated =
IF(Input[ContinuedFor]=BLANK(),
Input[DOJ],
LOOKUPVALUE(Input[DOL],Input[ID],Input[ContinuedFor])
)
DOL_Updated =
IF(Input[IsContinued]<>1,
Input[DOL],
IF(LOOKUPVALUE(Input[DOJ],Input[ContinuedFor],Input[ID])<>BLANK() ,LOOKUPVALUE(Input[DOJ],Input[ContinuedFor],Input[ID]),EOMONTH(UTCTODAY(),0) //LOOKUPVALUE(Input[DOJ],Input[ContinuedFor],Input[ID])
))

As you had suggested that this should not be done via DAX, so I was trying via fabric dataflow gen2 for my learning & using Power Query to get the desired result, however I was unable to find an alternative to LOOKUPVALUE in Power Query.

There are many ways to have the equivalent of LookupValue in Power Query.  What have you tried and where are you stuck?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.