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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
BarisT
Helper I
Helper I

Adding the last date to a new row as a new column in M for the same ID

Dear Power BI users,

 

I would like to add the enddate as a last enddate in the newest row for each employee that has the same employeeID (22671)with. How can I add a new column to perform the added column "Last enddate" that is always extracted from the previous row considering the same EmployeeID (22671)? I did this now by hand, but it should take the enddate of the previous row. The link to the power BI example is here: https://1drv.ms/u/s!Al86B9l3mXfCcDTX7RtpkYNR7pk?e=T4QvHOPreviousEnddate.JPG

 

Thank you for your help in advance. Much greats.

3 REPLIES 3
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XYtBDsAgCAT/wllCWcC2b2n8/zcqVRPTExtm5nlIvapRIaCe2q9xZRxAn9RKcg/d+M22OIJj7BSzza+KyhQUS16CfQJkYLnkF/sWB/uM2ws=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, EployeeID = _t, Startdate = _t, Enddate = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"EployeeID", Int64.Type}, {"Startdate", type date}, {"Enddate", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"EployeeID"}, {{"Max", each List.Max([Startdate]), type nullable date}, {"Last Enddate", each List.Min([Enddate]), type nullable date}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"EployeeID", "Startdate"}, #"Grouped Rows", {"EployeeID", "Max"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Last Enddate"}, {"Last Enddate"})
in
    #"Expanded Grouped Rows"

 

Hello,

 

No this is not what i want. You are now using last enddate as a column, but the exercise was to create that with only start and enddate. I hope I could explain it.

I have generated output as per your picture. So, I am wondering what output do you need.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors