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

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
hash86
Frequent Visitor

VLOOKUP with duplicate values in al column

Hello,
I am new to PowerBi and have come across a query where I need some help please.
I have a table with multiple ID and job roles and the start date for that job role.
I am looking to find for each ID, their first job role.
In Excel I can simply sort the start date by Oldest and then do a VLOOKUP on the ID. But I am not sure how this works in Power BI
Any help would be great.
Thank you 🙂

 

Data 

ID Job RoleStart Date 
1Cashier16/07/2022
2Supervisor 26/06/2022
2Cashier02/05/2022
3Cashier02/08/2022
3PT Sales Assistant12/03/2022
4FT Sales Assistant 20/02/2022
4PT Sales Assistant31/01/2022
4Cashier04/04/2022

 

 

Output Required 

 

ID Job Role
1Cashier
2Cashier
3PT Sales Assistant
4PT Sales Assistant
1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @hash86 ,

 

Create a new blank query and paste this over all the default code in Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJOLM7ITC0CsgzN9A3M9Y0MjIyUYnWilYyAQsGlBalFZZnF+UUKQJ4RUIEZqgKEbgMjfQNThKQxhqQFqmRAiEJwYk5qsYJjcXFmcUliXgnICUB1xgh1JkAhNwx1YKcY6APNRFGI1UBjQ30DQ1R1SK4y0QciiGQsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Job Role" = _t, #"Start Date" = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Job Role", type text}, {"Start Date", type date}}),

// Relevant steps ----->
    groupAllRows = Table.Group(chgTypes, {"ID"}, {{"data", each _, type table [#"ID"=nullable number, Job Role=nullable text, #"Start Date"=nullable date]}}),
    addMinRecord = Table.AddColumn(groupAllRows, "minRecord", each Table.Min([data], "Start Date")),
    expandMinRecord = Table.ExpandRecordColumn(addMinRecord, "minRecord", {"Job Role", "Start Date"}, {"Job Role", "Start Date"}),
// <----- Relevant steps

    remOthCols = Table.SelectColumns(expandMinRecord,{"ID", "Job Role"})
in
    remOthCols

 

Summary:

-1- Group the table on [ID] and add an 'All Rows' column.

-2- Pick out the the record that has the lowest [Start Date] from each nested table.

-3- Expand the new recod column reinstating your desired columns.

 

Example output:

BA_Pete_0-1689246989011.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

3 REPLIES 3
slorin
Super User
Super User

Hi

Group by ID and use Table.Min function

Table.Group(Previous_Step, {"ID"}, {{"Job Role", each Table.Min(_,"Start Date")[Job Role], type nullable text}})

Stéphane 

hash86
Frequent Visitor

@BA_Pete thank you so much 🙂

BA_Pete
Super User
Super User

Hi @hash86 ,

 

Create a new blank query and paste this over all the default code in Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJOLM7ITC0CsgzN9A3M9Y0MjIyUYnWilYyAQsGlBalFZZnF+UUKQJ4RUIEZqgKEbgMjfQNThKQxhqQFqmRAiEJwYk5qsYJjcXFmcUliXgnICUB1xgh1JkAhNwx1YKcY6APNRFGI1UBjQ30DQ1R1SK4y0QciiGQsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Job Role" = _t, #"Start Date" = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Job Role", type text}, {"Start Date", type date}}),

// Relevant steps ----->
    groupAllRows = Table.Group(chgTypes, {"ID"}, {{"data", each _, type table [#"ID"=nullable number, Job Role=nullable text, #"Start Date"=nullable date]}}),
    addMinRecord = Table.AddColumn(groupAllRows, "minRecord", each Table.Min([data], "Start Date")),
    expandMinRecord = Table.ExpandRecordColumn(addMinRecord, "minRecord", {"Job Role", "Start Date"}, {"Job Role", "Start Date"}),
// <----- Relevant steps

    remOthCols = Table.SelectColumns(expandMinRecord,{"ID", "Job Role"})
in
    remOthCols

 

Summary:

-1- Group the table on [ID] and add an 'All Rows' column.

-2- Pick out the the record that has the lowest [Start Date] from each nested table.

-3- Expand the new recod column reinstating your desired columns.

 

Example output:

BA_Pete_0-1689246989011.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
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors