The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I need to check if a value of one column exists in another column of the same table.
I need to apply VLOOKUP in Power Query.
With DAX, its possible but with Power Query, I am not able to find a proper solution.
Can someone please help me out?
Solved! Go to Solution.
Hi @Aayushi ,
In Power Query functions can be created like this:
(lookupValue as any, lookupTable as table, lookupColumnName as text, returnColumnValue as text) =>
let
// lookupTable= Products,
// lookupColumnName = "ProductKey",
// returnColumnValue = "Price",
// lookupValue = 1,
colLookup = Table.Column(lookupTable, lookupColumnName),
colToReturn = Table.Column(lookupTable, returnColumnValue),
lookup = List.PositionOf(colLookup, lookupValue, 0),
Result = if lookup >=0 then colToReturn{lookup} else "Not found"
in
Result
Or
You can duplicate your query and merge the two queries to get the desired columns.
Disable the load from the duplicate one to avoid performance issues.
Please refer to the following documents for more information.
#PowerQuery – Replicate doing an Excel VLOOKUP in M – Erik Svensen
How to do a real VLOOKUP (false) in Power Query or Power BI – The BIccountant
VLOOKUP / XLOOKUP in Power Query - Bing video
VLOOKUP in Power Query Using List Functions - Bing video
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I was trying to do this all in M code - because I didn't want to make the actual table and then join ... wanted it all in the M query (Advanced editor). **My lookup table has no duplicates (in fact, there's a step to remove duplicates just to be sure. If there were duplicates, the code below would not be perfect.
I landed with this code that is working:
CombinedTable = Table.AddColumn(TableAlmostDone, "UserResponsible_StaffKey", each DimMarketStaff[StaffKey]{List.PositionOf(DimMarketStaff[StaffName], [UserResponsible])}),
FinalTable = Table.ReplaceErrorValues(CombinedTable, {{"UserResponsible_StaffKey", 0}})
Hi @Aayushi ,
In Power Query functions can be created like this:
(lookupValue as any, lookupTable as table, lookupColumnName as text, returnColumnValue as text) =>
let
// lookupTable= Products,
// lookupColumnName = "ProductKey",
// returnColumnValue = "Price",
// lookupValue = 1,
colLookup = Table.Column(lookupTable, lookupColumnName),
colToReturn = Table.Column(lookupTable, returnColumnValue),
lookup = List.PositionOf(colLookup, lookupValue, 0),
Result = if lookup >=0 then colToReturn{lookup} else "Not found"
in
Result
Or
You can duplicate your query and merge the two queries to get the desired columns.
Disable the load from the duplicate one to avoid performance issues.
Please refer to the following documents for more information.
#PowerQuery – Replicate doing an Excel VLOOKUP in M – Erik Svensen
How to do a real VLOOKUP (false) in Power Query or Power BI – The BIccountant
VLOOKUP / XLOOKUP in Power Query - Bing video
VLOOKUP in Power Query Using List Functions - Bing video
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
hi @Aayushi
It is call merge in Power Query, check this:
https://learn.microsoft.com/en-us/power-query/merge-queries-left-outer
Thanks legend
User | Count |
---|---|
77 | |
75 | |
36 | |
31 | |
29 |
User | Count |
---|---|
94 | |
80 | |
55 | |
48 | |
48 |