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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

VLookup in Power Query

Good afternoon. I am working through modifying a vlookup for power query and am runninginto issues.

 

Goal: Fill in mgr grade_rank with the manager's grade rank. 

 

Method: Match mgr_emplid and Employee ID columns and return the value in the grade_rank column. 

 

In the below example, I matched the mgr_emplid "1313" with the Employee ID "1313" and returned the value of "5" to mgr grade_rank. 

 

I know how to do it in excel, but am struggling to do it in powerquery as Lookup and Match functions. Any help would be appreciated.

 

Current version: 

Mgr Grade Rank = LOOKUPVALUE(Main[grade_rank],Main[mgr_emplid],Main[Employee ID],0)   Then how do I add the match in and return the value?  Thank you.

 

 

Out4uv8_0-1597177197207.png

 

 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

THe easiest way to do this in Power Query is to merge the table with itself, but merge the Manager ID column with the Employee ID coluimn, then expand the grade.

edhans_0-1597181742403.png

Then expand that field only.

edhans_1-1597181822757.png

 

I see your example is using LOOKUPVALUE() - that is a DAX function, and you can use this as a calculated column:

Column = 
LOOKUPVALUE(
    [Grade],
    [EmployeeID],
    [mgrID]
)

It will return this:

edhans_0-1597182039186.png

But I recommend against it. In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
Calculated Columns vs Measures in DAX
Calculated Columns and Measures in DAX
Storage differences between calculated columns and calculated tables

Avoid the temptation to work in the Data view and create a bunch of calculated columns like you would think of when using Excel when you just add another column. Power BI is very different and that is not a good practice to get into. Try to use Power Query for transformations and bringing in new data, and Measures for data analysis. Avoid Calculated Columns where possible.

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , refer

https://eriksvensen.wordpress.com/2019/02/28/powerquery-replicate-doing-an-excel-vlookup-in-m/

https://www.myonlinetraininghub.com/excel-power-query-vlookup

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

try to adapt this code

 image.png

edhans
Super User
Super User

THe easiest way to do this in Power Query is to merge the table with itself, but merge the Manager ID column with the Employee ID coluimn, then expand the grade.

edhans_0-1597181742403.png

Then expand that field only.

edhans_1-1597181822757.png

 

I see your example is using LOOKUPVALUE() - that is a DAX function, and you can use this as a calculated column:

Column = 
LOOKUPVALUE(
    [Grade],
    [EmployeeID],
    [mgrID]
)

It will return this:

edhans_0-1597182039186.png

But I recommend against it. In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
Calculated Columns vs Measures in DAX
Calculated Columns and Measures in DAX
Storage differences between calculated columns and calculated tables

Avoid the temptation to work in the Data view and create a bunch of calculated columns like you would think of when using Excel when you just add another column. Power BI is very different and that is not a good practice to get into. Try to use Power Query for transformations and bringing in new data, and Measures for data analysis. Avoid Calculated Columns where possible.

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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