+ Reply to Thread
Results 1 to 7 of 7

Remove all but one instance of a value in one column based on records in another colu

  1. #1
    Registered User
    Join Date
    04-30-2010
    Location
    Wales, Boyo
    MS-Off Ver
    Excel 2007
    Posts
    42

    Remove all but one instance of a value in one column based on records in another colu

    Hopefully the post title makes sense.

    I have some vba which returns a result set from a sql database.

    The sales data has each line from a customer order (with the order number in column B) Now depending on the size of the order there may be ten or more lines. Each record in the database has the shipping cost allocated to it for the whole order. The query returns hundreds of sales orders into a table.

    So if one particulat order was 10 lines and the total shipping cost was 100, then each of the ten lines will have the 100 value against it.

    I am trying to figure out a way to remove all but one of the shipping costs for any given sales order. As i mentioned the sales order number is in column B.

    Hope someone can point me in the right direction

    thanks in advance
    Last edited by TheCyrusVirus; 10-20-2010 at 11:33 AM.

  2. #2
    Registered User
    Join Date
    04-30-2010
    Location
    Wales, Boyo
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Remove duplicates from one column based on entries in another column

    sample sheet now attached to show the data, hope someone can help me as I desperately need to get this working

    Thanks in advance
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    04-30-2010
    Location
    Wales, Boyo
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Remove all but one instance of a value in one column based on records in another

    Could I read the value of the sales order into a variable and use offset to loop through the rows where the sales order is equal and delete all but the first one?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Remove all but one instance of a value in one column based on records in another

    In your sample - the implication is that L2:L5 are the same transaction yet each has a different order number - is that an oversight ?

    So to be clear - the aim is to alter the duplicate transports such that they become 0, correct ?
    If on the other hand you're removing the duplicate rows physically would this not distort the other values like Amount, Quantity etc which are unique to each line ?

    I guess it would help if we knew how these values are to be used ? Why do you need to remove the duplicates etc...

    For ex. =AVERAGEIF(L:L,B:B,<order no>) would give you the Average Shipping Cost for a given Order which would be correct obviously (SUM would not).

    (pending answers to above it might be worth amending the SQL directly...)
    Last edited by DonkeyOte; 10-20-2010 at 07:38 AM. Reason: typo

  5. #5
    Registered User
    Join Date
    04-30-2010
    Location
    Wales, Boyo
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Remove all but one instance of a value in one column based on records in another

    Sorry yes thats an oversight.

    Yes I need to 0 all but one of the transport costs.

    This then feeds into a pivot table which shows profitability by month. (sales amount - cost prices - transport costs)

    The main problem i have is that the data is stored in sql in a varchar column and sql doesnt seem to like performing calcs on this directly.

    So when I extract into excel I convert to a number format and then wanted to remove the duplicate transport costs from all of the orders so that when i calculate the profitability by month I wasnt including the transport costs multiple times.

    How could I use that average function in a new column but only populate it once for each order?

    Thanks for your help so far and sorry for the confusion my oversight caused.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Remove all but one instance of a value in one column based on records in another

    I confess I've not the time to play around with the Pivot to see if you could use the Average in a Calculated Field.

    If you opt for the new field then:

    Please Login or Register  to view this content.
    this will apportion the cost such that when the order is aggregated it equates to total cost
    (the above assumes as inferred that all order lines are collated together)

    edit:
    I should have added that if you really wanted to 0 rather than apportion across duplicates then change M1 to 0 and L2/COUNTIF() to just L2
    Last edited by DonkeyOte; 10-20-2010 at 07:35 AM.

  7. #7
    Registered User
    Join Date
    04-30-2010
    Location
    Wales, Boyo
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Remove all but one instance of a value in one column based on records in another

    Perfect, thanks very much. Will mark it as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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