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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
JP8991
Advocate V
Advocate V

Employee Data - Tenure in Current Role and Current Location

Hello All,

I looking to create two new columns, preference would be Power Query but happy with DAX too.

The columns would be:

 

  • Tenure in Current Role
  • Tenure in Current Role and Location

 

I have highlighted them below to help explain what I mean.

 

JP8991_0-1622527654666.png

 

Thanks,

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @JP8991 

Create a blank query, open its Advanced Editor and clear the codes in it. Then copy and paste below codes to check the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc/BCoMwDAbgV5GchSatbvXoPHvzJj2UUZyXHmzfH20nLTjddkpIvvyQcYQWSqiZIMaR09YTYiidsX4xRa+tnswS56DKN6+YwF+8SVr8ES6jfmwdZ1we9GD08xXZPTH6DM3slhnfHZ65OrourGh/6dRV2eG3PJFccxE326lonZud19aHb9OFvAg+XhAotQI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Location = _t, #"Period End Date" = _t, #"Employee ID" = _t, #"Job Title" = _t, Tenure = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Period End Date", type date}, {"Employee ID", Int64.Type}, {"Job Title", type text}, {"Tenure", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Employee ID", "Job Title"}, {{"Alldata", each _, type table [Location=nullable text, Period End Date=nullable date, Employee ID=nullable number, Job Title=nullable text, Tenure=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn(Table.Sort([Alldata],{"Tenure",Order.Ascending}),"Tenure in Current Role",1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Alldata"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Location", "Period End Date", "Tenure", "Tenure in Current Role"}, {"Location", "Period End Date", "Tenure", "Tenure in Current Role"}),
    #"Grouped Rows1" = Table.Group(#"Expanded Custom", {"Employee ID", "Location", "Job Title"}, {{"Alldata2", each _, type table [Employee ID=nullable number, Job Title=nullable text, Location=text, Period End Date=date, Tenure=number, Tenure in Current Role=number]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows1", "Custom2", each Table.AddIndexColumn(Table.Sort([Alldata2],{"Tenure",Order.Ascending}),"Tenure in Current Role and Location",1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Alldata2"}),
    #"Expanded Custom2" = Table.ExpandTableColumn(#"Removed Columns1", "Custom2", {"Period End Date", "Tenure", "Tenure in Current Role", "Tenure in Current Role and Location"}, {"Period End Date", "Tenure", "Tenure in Current Role", "Tenure in Current Role and Location"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Custom2",{{"Tenure", Order.Descending}})
in
    #"Sorted Rows"

v-jingzhang_0-1622698050344.png

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @JP8991 

Create a blank query, open its Advanced Editor and clear the codes in it. Then copy and paste below codes to check the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc/BCoMwDAbgV5GchSatbvXoPHvzJj2UUZyXHmzfH20nLTjddkpIvvyQcYQWSqiZIMaR09YTYiidsX4xRa+tnswS56DKN6+YwF+8SVr8ES6jfmwdZ1we9GD08xXZPTH6DM3slhnfHZ65OrourGh/6dRV2eG3PJFccxE326lonZud19aHb9OFvAg+XhAotQI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Location = _t, #"Period End Date" = _t, #"Employee ID" = _t, #"Job Title" = _t, Tenure = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Period End Date", type date}, {"Employee ID", Int64.Type}, {"Job Title", type text}, {"Tenure", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Employee ID", "Job Title"}, {{"Alldata", each _, type table [Location=nullable text, Period End Date=nullable date, Employee ID=nullable number, Job Title=nullable text, Tenure=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn(Table.Sort([Alldata],{"Tenure",Order.Ascending}),"Tenure in Current Role",1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Alldata"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Location", "Period End Date", "Tenure", "Tenure in Current Role"}, {"Location", "Period End Date", "Tenure", "Tenure in Current Role"}),
    #"Grouped Rows1" = Table.Group(#"Expanded Custom", {"Employee ID", "Location", "Job Title"}, {{"Alldata2", each _, type table [Employee ID=nullable number, Job Title=nullable text, Location=text, Period End Date=date, Tenure=number, Tenure in Current Role=number]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows1", "Custom2", each Table.AddIndexColumn(Table.Sort([Alldata2],{"Tenure",Order.Ascending}),"Tenure in Current Role and Location",1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Alldata2"}),
    #"Expanded Custom2" = Table.ExpandTableColumn(#"Removed Columns1", "Custom2", {"Period End Date", "Tenure", "Tenure in Current Role", "Tenure in Current Role and Location"}, {"Period End Date", "Tenure", "Tenure in Current Role", "Tenure in Current Role and Location"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Custom2",{{"Tenure", Order.Descending}})
in
    #"Sorted Rows"

v-jingzhang_0-1622698050344.png

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

@v-jingzhang wow this is amazing!

Excatly what I wanted, thank you so much.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors