• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Lookup to nearest matching value|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Lookup to nearest matching value|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryLookup to nearest matching value
sp_PrintTopic sp_TopicIcon
Lookup to nearest matching value
Avatar
baxbax
Member
Members

Power Query

Power Pivot
Level 0
Forum Posts: 105
Member Since:
July 11, 2016
sp_UserOfflineSmall Offline
1
March 29, 2019 - 8:06 pm
sp_Permalink sp_Print

Hi,

Is there a way to add the nearest matching value to a row similar to Excel VLOOKUP approximate match?

I have a data set that shows the weights and dimensions of products. In some instances the weight is missing but I have another table that shows an average weight based on the products diagonal size. I want to populate the missing weight fields with the average one using the diagonal size which is a field that exists in both tables. However the diagonal size values do not match exactly so I want to pick up the weight from the nearest diagonal size.

For example in the data set I have an item with no weight where the diagonal size is 22 inches. In the average weight table it shows that the average weight for a 20 inch product is 5kg and for a 30 inch product it is 10kg. I want to pick up the weight of the nearest matching item so in this instance it would be 5kg.

I have attached a file showing some example data.

Thanks

 

Bax

Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 870
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
2
March 30, 2019 - 2:37 am
sp_Permalink sp_Print

Hello,

I don't see any query in your file, so below is the Excel formula I assume you want.

=VLOOKUP(MROUND(I8,10),Table_Lookup,2,TRUE)

Click respective link to read more about MROUND and VLOOKUP.

Br,

Anders

Avatar
baxbax
Member
Members

Power Query

Power Pivot
Level 0
Forum Posts: 105
Member Since:
July 11, 2016
sp_UserOfflineSmall Offline
3
March 30, 2019 - 8:06 pm
sp_Permalink sp_Print

Hi Anders,

File attached now has a query added. I want to somehow combine the two queries in the file to fill in the missing weights in the Query_data table.

Thanks

 

Bax

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
March 30, 2019 - 8:27 pm
sp_Permalink sp_Print

Hi baxbax,

you can use the following function, that replicates the nearest match lookup:

(Parameter)=>
let
Source = Excel.CurrentWorkbook(){[Name="Table_Lookup"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Diagonal (in)", type number}, {"Weight (kg)", type number}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Diagonal (in)", Order.Descending}}),
#"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each [#"Diagonal (in)"] <= Parameter),
Group = #"Filtered Rows"{0}[#"Weight (kg)"]
in
Group

Avatar
baxbax
Member
Members

Power Query

Power Pivot
Level 0
Forum Posts: 105
Member Since:
July 11, 2016
sp_UserOfflineSmall Offline
5
April 1, 2019 - 6:08 pm
sp_Permalink sp_Print

Hi Catalin,

Your solution works really well. Do you have any explanation as to how this works as I would like to understand it a bit more so I can use in future.

Thanks

 

Bax

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
6
April 1, 2019 - 9:42 pm
sp_Permalink sp_Print

The function is selecting only the rows from the lookup table where the Diagonal is smaller than the parameter passed to this function:

Table.SelectRows(#"Sorted Rows", each [#"Diagonal (in)"] <= Parameter),

Because this table is already sorted descending, the very first row will contain our needed value: ({0} means first row, it's zero based)

Group = #"Filtered Rows"{0}[#"Weight (kg)"]

Avatar
baxbax
Member
Members

Power Query

Power Pivot
Level 0
Forum Posts: 105
Member Since:
July 11, 2016
sp_UserOfflineSmall Offline
7
April 2, 2019 - 7:13 pm
sp_Permalink sp_Print

Hi Catalin,

Thanks for taking the time to add the explanation. It really helps. 

Bax

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Andy Kirby, Jill Niemeier, Laxmi Praveen
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
yashal minahil
Oluwadamilola Ogun
Yannik H
dectator mang
Francis Drouillard
Orlando Inocente
Jovitha Clemence
Maloxat Axmatovna
Ricardo Freitas
Marko Meglic
Forum Stats:
Groups: 3
Forums: 24
Topics: 6201
Posts: 27185

 

Member Stats:
Guest Posters: 49
Members: 31861
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.