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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
Mark-JZ-Yeap
Helper I
Helper I

Please delete this post

I am unable to delete this post. Please assist.

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Mark-JZ-Yeap ,

 

Try this M code (not DAX) in a new blank query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY5LEsAgCEPvwtoZAv7aszje/xoVtY62O5IXAqWQkCO9GJkVqiYi4zbhm6DqCnXXb64HixwRG6AsWO4EYcQRXyC/+jiP6orgG0ljUXSrD51kOxz3d1pZJ5eRdO5QrQ8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, DOJ = _t, DOL = _t, ContinuedFor = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"DOJ", type date}, {"DOL", type date}, {"ContinuedFor", Int64.Type}, {"Employee ID", Int64.Type}}),

// Relevant steps from here =====>
    mergeOnSelf = Table.NestedJoin(chgTypes, {"Employee ID"}, chgTypes, {"ContinuedFor"}, "nextEmp", JoinKind.LeftOuter),
    expandDOJ = Table.ExpandTableColumn(mergeOnSelf, "nextEmp", {"DOJ"}, {"DOL_Updated"}),
    repDOL_Updated = Table.ReplaceValue(expandDOJ, each [DOL_Updated], each if [DOL_Updated] > [DOL] then Date.EndOfMonth(Date.AddMonths([DOL_Updated], -1)) else null, Replacer.ReplaceValue,{"DOL_Updated"})
in
    repDOL_Updated

 

Summary:

mergeOnSelf = Left outer merge the table on itself as [Employee ID] = [ContinuedFor].

expandDOJ = Expand the [DOJ] column from the nested table column (I also renamed it to DOL_Updated at the same time).

repDOL_Updated = Perform a conditional replace on the [DOL_Updated] column applying the required logic.

 

Example code turns this:

BA_Pete_0-1716969208767.png

 

...into this:

BA_Pete_1-1716969240598.png

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

1 REPLY 1
BA_Pete
Super User
Super User

Hi @Mark-JZ-Yeap ,

 

Try this M code (not DAX) in a new blank query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY5LEsAgCEPvwtoZAv7aszje/xoVtY62O5IXAqWQkCO9GJkVqiYi4zbhm6DqCnXXb64HixwRG6AsWO4EYcQRXyC/+jiP6orgG0ljUXSrD51kOxz3d1pZJ5eRdO5QrQ8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, DOJ = _t, DOL = _t, ContinuedFor = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"DOJ", type date}, {"DOL", type date}, {"ContinuedFor", Int64.Type}, {"Employee ID", Int64.Type}}),

// Relevant steps from here =====>
    mergeOnSelf = Table.NestedJoin(chgTypes, {"Employee ID"}, chgTypes, {"ContinuedFor"}, "nextEmp", JoinKind.LeftOuter),
    expandDOJ = Table.ExpandTableColumn(mergeOnSelf, "nextEmp", {"DOJ"}, {"DOL_Updated"}),
    repDOL_Updated = Table.ReplaceValue(expandDOJ, each [DOL_Updated], each if [DOL_Updated] > [DOL] then Date.EndOfMonth(Date.AddMonths([DOL_Updated], -1)) else null, Replacer.ReplaceValue,{"DOL_Updated"})
in
    repDOL_Updated

 

Summary:

mergeOnSelf = Left outer merge the table on itself as [Employee ID] = [ContinuedFor].

expandDOJ = Expand the [DOJ] column from the nested table column (I also renamed it to DOL_Updated at the same time).

repDOL_Updated = Perform a conditional replace on the [DOL_Updated] column applying the required logic.

 

Example code turns this:

BA_Pete_0-1716969208767.png

 

...into this:

BA_Pete_1-1716969240598.png

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.