Forum

VLOOKUP in Power Qu...
 
Notifications
Clear all

VLOOKUP in Power Query using List Functions

3 Posts
2 Users
0 Reactions
242 Views
(@kviccaji)
Posts: 2
New Member
Topic starter
 

Hi, I recently used the technique outlined in Phil's post here:

VLOOKUP in Power Query Using List Functions • My Online Training Hub

It was really helpful to me, and I have already applied it in a couple of my files.

In Phil's example file the Sales value in the Sales_Data table is looked up in the BonusRates table.
And based on this value, the bonus rate (%) is returned into the Power Query results table (Sales_Bonuses table).

Now, in this example, the field being looked up is "Sales" without any spaces.

However, in my files, I have field names with spaces (e.g. "Income (in USD)" or "Time of Record", etc.).

In such a case, the M Code gives an error because the field name includes spaces.

To replicate this error, I changed the field header from Sales to "Sales Value" in the example file uploaded on the MOTH website.

The error occurs in the M-Code line

= Table.AddColumn(#"Changed Type", "BonusRates", each let val = [Sales] in List.Select( BonusRates[Threshold] , each _ <= val ))

In this line, the field name "Sales" needs to be "Sales Value".
But I am not able to figure out the correct syntax and get the M Code to work.

I have attached the example file with this change, along with screenshots of the error I'm getting.

 

Please help!

~KV

MOTH-PQ-Approx-lookup-on-field-name-with-space-01-1.jpgMOTH-PQ-Approx-lookup-on-field-name-with-space-02-1.jpgMOTH-PQ-Approx-lookup-on-field-name-with-space-03-1.jpg

 
Posted : 20/07/2024 10:53 am
Riny van Eekelen
(@riny)
Posts: 1208
Member Moderator
 

In the Added Custom1 step of the Sales_Bonuses query, just enter the column name as it is between square brackets.

let val = [Sales Value] in List.Select( BonusRates[Threshold] , each _ <= val )
 
No need for quotation marks or any other special notation.
 
Even easier, when you construct such a line of code in the 'Custom column' window, just double-click on the column name you want to insert. PQ will automatically enter the column name with the square brackets.
 
Posted : 21/07/2024 1:17 am
(@kviccaji)
Posts: 2
New Member
Topic starter
 

Many thanks @Riny Van Eekelen!

It works perfectly now!

I'm feeling really goofy about this... Embarassed
Such a simple solution staring me in the face, and it never occurred to me! Smile

Perhaps I was over-thinking about the "spaces in field headings" bit, and never thought of inserting the column name from the Custom Column settings dialog!

 
Posted : 21/07/2024 9:25 am
Share: