+ Reply to Thread
Results 1 to 5 of 5

Remove duplicates by condition

  1. #1
    Forum Contributor
    Join Date
    02-03-2020
    Location
    Wisconsin
    MS-Off Ver
    365
    Posts
    150

    Remove duplicates by condition

    Hello, Can anyone help me (if this is even possible) to remove duplicates conditionally? Here is what I have:

    A workbook that I imported data from my system at work. In column A there are order numbers, and column B are codes for things that happened within that order.

    I only want 1 code per order, and there are many duplicates. However, I want certain codes to take precedence.

    Example: Work order # 347090 has 3 entries. L06, L15, and W21. I want to remove the 2 entries that start with L, and keep the W21.

    There are many example like this. On page 2 of the workbook I have a list of "exceptions" - meaning I want to see those codes and not necessarily remove them.

    So I guess the rule would be:

    Remove duplicate rows based on column A unless column B is equal to an exception code (which are defined on page 2 - column A)

    There may be another part to this. If this first part is successful, you will see some order duplicates that remain. Some of them will have the same exception code listed twice. Example: Order 347674 has 12 entries - ALLL 12 of them are exception codes. But I only need 1, and it doesnt matter which 1 I keep. So if I had to express part 2 in terms of logic I would say:

    Once the previous rule is complete - For remaining duplicate values in column A where ONLY exception codes remain - keep the most recent (Columns C and D)

    As I type this I'm leaning towards this needing a macro, or VBA. If so, please let me know so it can move to the proper forum.

    Thank you in advance for any and all help!
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,940

    Re: Remove duplicates by condition

    With Power Query, bring each table into the PQ Editor and then join the two tables with a Left Outer Join. Next remove all duplicates.

    See the attached file to analyze these steps.

    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    02-03-2020
    Location
    Wisconsin
    MS-Off Ver
    365
    Posts
    150

    Re: Remove duplicates by condition

    First of all, thank you for this. I don't know much about power query, a little intimidated by it. However, I don't think this worked.

    example: Sales Order # 351866 - This order does NOT have a duplicate value. Yet it has been removed from the new "Merge1" list. Its reason code is "S17"
    also 352162 is not showing either. It is NOT a duplicate, but its reason code is not on the exception list.

    It looks like the power query removed all codes that weren't on the list. I apologize if I did a poor job explaining, I would like ONLY duplicates removed. If there is a solo order number, that can stay regardless of the reason code. Is there a way to adjust it so that happens?

    Thanks again!

  4. #4
    Registered User
    Join Date
    01-09-2022
    Location
    Monterrey Mexico
    MS-Off Ver
    office 365
    Posts
    13

    Re: Remove duplicates by condition

    Hello!

    I tried to do it with power query, hope it works

    regards,
    alan
    Attached Files Attached Files

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Remove duplicates by condition

    Try below code.
    If it does not work, attach file again with manual outcome (just few representative rows is enough).
    HTML Code: 
    Attached Files Attached Files
    Quang PT

+ 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. Compare lists of URLs for duplicates, and remove duplicates
    By mrfranklin in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-25-2021, 02:54 AM
  2. [SOLVED] Remove duplicates by condition
    By jonas-martens in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2021, 04:32 PM
  3. Replies: 6
    Last Post: 11-27-2018, 07:17 AM
  4. How To Remove Duplicates On Specific Condition?
    By TechnicGeek in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-15-2014, 02:12 PM
  5. Replies: 1
    Last Post: 10-23-2012, 09:12 AM
  6. Replies: 5
    Last Post: 02-28-2012, 02:52 PM
  7. Replies: 2
    Last Post: 03-20-2011, 11:19 AM

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