+ Reply to Thread
Results 1 to 10 of 10

Power Query - Join Two tables using NOT EQUAL criteria

  1. #1
    Registered User
    Join Date
    04-16-2020
    Location
    England
    MS-Off Ver
    Office 386
    Posts
    14

    Power Query - Join Two tables using NOT EQUAL criteria

    Hello,

    I am really hoping someone is able to help with this issue I am facing.

    I have two tables in Excel, an extract of these table is described below.

    Table 1 - Columns
    assetId,
    startLocationId,
    endLocationId

    Table 2 - Columns
    assetId,
    homeLocationId

    what I want to do is the equivalent for this....

    Please Login or Register  to view this content.

    I have a NestedJoin in the Power Query Editor which does most of the work except for the last <> comparison, I do not know how to do this and I am struggling to find anything on the web about it.

    Please Login or Register  to view this content.
    There is something I have found called
    Please Login or Register  to view this content.
    from the Microsoft Docs website "docs.microsoft.com/en-us/powerquery-m/table-nestedjoin"
    But no examples or what options there are.

    Any help is greatly appreciated.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    79,368

    Re: Power Query - Join Two tables using NOT EQUAL criteria

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    04-16-2020
    Location
    England
    MS-Off Ver
    Office 386
    Posts
    14

    Re: Power Query - Join Two tables using NOT EQUAL criteria

    Hi, Thanks, i'll knock up a quick sample now.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    79,368

    Re: Power Query - Join Two tables using NOT EQUAL criteria

    Will have a look when it appears.

  5. #5
    Registered User
    Join Date
    04-16-2020
    Location
    England
    MS-Off Ver
    Office 386
    Posts
    14

    Re: Power Query - Join Two tables using NOT EQUAL criteria

    Example Sheet Document Attached.

    Let me know if any more information will help.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-16-2020
    Location
    England
    MS-Off Ver
    Office 386
    Posts
    14

    Re: Power Query - Join Two tables using NOT EQUAL criteria

    Thanks, I appreciate it, have fun!!!

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    79,368

    Re: Power Query - Join Two tables using NOT EQUAL criteria

    Basic stuff!!!

    M Code:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Power Query - Join Two tables using NOT EQUAL criteria

    edit: ignore - ref. prior post

    Hi, one option would to be add a conditional column to your first table - to flag those records that haven't moved, and remove them:

    Please Login or Register  to view this content.
    then, merge that (as new) with the other table c/o inner join on asset and start=home; the output of which would mirror your expected results.

  9. #9
    Registered User
    Join Date
    04-16-2020
    Location
    England
    MS-Off Ver
    Office 386
    Posts
    14

    Re: Power Query - Join Two tables using NOT EQUAL criteria

    This is awesome, I have been struggling with getting my head around how Power Query works and with this one example I think I finally get it.

    I have been expecting it to be similar to T-SQL and other programming languages but it isn't, basically you have to break each step down to its constituent parts, I was just expecting to be able to say join TableA with TableB where these things are TRUE.

    I can see in your example (thanks for this) that you have broken it down as the following:
    • Join tables on single key (assetId)
    • Expand table to get the Home Location
    • Add new Column which evaluates the selection criteria (start = home AND end <> home)
    • Filter only the stuff which match both criteria

    Strangely enough whist you were working on this I was doing exactly the same thing in the actual Excel workbook with VLookups and some additional fields.

    I think I have learnt a lot from this simple example. I need to change my mindset when dealing with Power Query.

    Thanks for your help, you may pat yourself on the back

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    79,368

    Re: Power Query - Join Two tables using NOT EQUAL criteria

    Thanks for that. PQ is Pandora's Box - once opened, ...

    I use it extensively almost every day, so I'm getting pretty good at it, but there's so much to learn. I really like it - mixing clicks in the UI and bits of bespoke M Code is fun.

    Enjoy getting to know it better!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Power Query: Updating a query based on changing tables
    By cheesehead101 in forum Excel General
    Replies: 1
    Last Post: 12-16-2019, 06:54 PM
  2. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM
  3. Power Query tables in VBA
    By orhanceliloglu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-26-2018, 08:25 AM
  4. [SOLVED] Multiple tasks on tables in Power Query
    By wrybel in forum Excel General
    Replies: 11
    Last Post: 08-01-2017, 03:17 AM
  5. Power Query - how to append tables
    By GIS2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2015, 04:55 AM
  6. [SOLVED] Power Pivot join tables question
    By ericedholm in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-09-2013, 10:53 AM
  7. Access Query NOT EQUAL Join
    By dash11 in forum Access Tables & Databases
    Replies: 5
    Last Post: 04-19-2013, 10:59 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1