Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

End date for each start date by person

Hello

 

I am trying to add a custom column that will give me the "Date Effective To" for each person below, depending on the start date of the next grade. Data I am working with:

NameIDDate Effective FromGrade
Joe BloggsA00101/01/2025Z100
Joe BloggsA00101/06/2025Z101
Joe BloggsA00101/01/2026Z102
Joe BloggsA00112/12/2026Z103
Jill JoggsA00201/01/2024Z101
Jill JoggsA00206/06/2024Z102
Jill JoggsA00201/01/2025Z103
Jill JoggsA00201/01/2026Z105

 

Requirement is to have an extra column with the date effective to, considering the person (by ID rather than name) and their next start date.

 

Thank you very Much

  • let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8spPVXDKyU9PL1bSUXI0MDAEUgaG+kBkZGBkCuREGRoYKMXq4FZphqTSEK9KsJlmEJVGOFUaGukDEUKlMURlZk6OghdCpRGymSYotmNTaQZ1pwmK7fjMNCXadqg7TZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, ID = _t, #"Date Effective From" = _t, Grade = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date Effective From", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Date Effective To", (k)=> List.Min(Table.SelectRows(#"Changed Type",each [ID]=k[ID] and [Date Effective From]>k[Date Effective From])[Date Effective From])-#duration(1,0,0,0),type date)
    in
        #"Added Custom"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

2 Replies

  • let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8spPVXDKyU9PL1bSUXI0MDAEUgaG+kBkZGBkCuREGRoYKMXq4FZphqTSEK9KsJlmEJVGOFUaGukDEUKlMURlZk6OghdCpRGymSYotmNTaQZ1pwmK7fjMNCXadqg7TZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, ID = _t, #"Date Effective From" = _t, Grade = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date Effective From", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Date Effective To", (k)=> List.Min(Table.SelectRows(#"Changed Type",each [ID]=k[ID] and [Date Effective From]>k[Date Effective From])[Date Effective From])-#duration(1,0,0,0),type date)
    in
        #"Added Custom"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

  • Hi Anonymous 

    Your question is not clear for me, can you provide your target table?