+ Reply to Thread
Results 1 to 10 of 10

subtracting 2 columns of data from each other when labels in separate columns match

  1. #1
    Registered User
    Join Date
    02-20-2009
    Location
    bristol, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    subtracting 2 columns of data from each other when labels in separate columns match

    Hi All,

    I desperately need some help.

    I have four columns of data, as follows:

    label 1, value 1, label 2, value 2

    I need to create a formula in the fith column that for each line will tell excel to:

    look for entry in 'label 1' in 'label 2'
    if there is a match, then subtract value 1 from value 2,
    display result.

    I have tried doing this with SUMIF but am getting nowhere fast.

    Any advice in arranging this is much appreciated, below is an example of the data:

    OPP IDs Value Opportunity Value 2
    1-1W9ODJT 54799 1-27OWHAC 3,000.00
    1-2CWNICU 13500 1-2CWNICU 25,088.00
    1-2L2MPVN 65600 1-2L2MPVN 124,272.00
    1-2N869TM 0 1-2N869TM 500
    1-2ROUMMB 30000 1-2ROUMMB 30,000.00
    1-2SKKX7Q 51855 1-2SJN6EP 13,178.00
    1-3TDP1JJ 250 1-3508L31 60
    1-3THRLYP 0 1-3N23YEQ 1,000.00
    1-3UD4V1Q 4491 1-3TDP1JJ 360
    1-3X0RXUM 4451 1-3THRLYP 1
    1-3ZI81IM 12306 1-3UCFCSH 100


    I have attached an excel spreadsheet showing the actual data this needs to be performed on (the complete spreadsheet contains several hundered rows of data)
    Attached Files Attached Files
    Last edited by hisnibs; 02-28-2009 at 12:07 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: subtracting 2 columns of data from each other when labels in separate columns mat

    Are you looking at this line by line...or are you summing all matches and subtracting sums?

    If the former... maybe:

    =IF(A3=C3,D3-B3,"") copied down

    if the latter...maybe:

    =IF(COUNTIF($A$3:$A$17,C3),SUMIF($A$3:$A$17,C3,$D$3:$D$17)-SUMIF($A$3:$A$17,C3,$B$3:$B$17),"")

    or maybe:

    =IF(COUNTIF($A$3:$A$17,C4),SUMPRODUCT(--($A$3:$A$17=C4),$D$3:$D$17-$B$3:$B$17),"")

    copied down.

    Test all 3 for expected results...
    Last edited by NBVC; 02-20-2009 at 01:02 PM.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    02-20-2009
    Location
    bristol, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: subtracting 2 columns of data from each other when labels in separate columns mat

    Hi Thanks for your help with this.

    the results are very close to what I would expect, but seem to go awry where the cells are not on the same row...

    I will have a look at this again and get back to you with any progress.



    Jim

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: subtracting 2 columns of data from each other when labels in separate columns mat

    I read it differently, and got this:

    =IF(ISERROR(MATCH(C3,$A$3:$A$17,0)),"",D3-INDEX($B$3:$B$17,MATCH(C3,$A$3:$A$17,0)))

    Adjusted for 100s of rows of data:

    =IF(ISERROR(MATCH(C3,$A$3:$A$500,0)),"",D3-INDEX($B$3:$B$500,MATCH(C3,$A$3:$A$500,0)))
    Last edited by JBeaucaire; 02-21-2009 at 02:42 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    02-20-2009
    Location
    bristol, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: subtracting 2 columns of data from each other when labels in separate columns mat

    Hi JBeaucaire

    That formula works perfectly! Thank you so much for helping me to resolve this.


    Now, to complicate matters further, can anyone suggest a way I can amend the formula to also flag up any items that are in column C but not in column A?

    Just to explain. We need to do this as the larger dataset represents sales made, whilst the smaller represents sales paid on so not only do we need to check that the figures match (as arranged by your formula), but we also need to check that we have been paid on all items (as per this requested amendment).

    Many thanks,


    Jim

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: subtracting 2 columns of data from each other when labels in separate columns mat

    Actually, that formula I gave already does that. It is returning a blank row for the ones that are in column C but not in A. So you can spot them already. Or you can change the formula to this to really do it:

    =IF(ISERROR(MATCH(C3,$A$3:$A$500,0)),"No Match",D3-INDEX($B$3:$B$500,MATCH(C3,$A$3:$A$500,0)))

    Another way is to highlight all the column C data from C3 down and apply this conditional formatting:

    Condition1: Formula Is: =COUNTIF($A$3:$A$500,C3)=0
    ...and set a format for background color like yellow.

    Now if the item in column C is missing from column A, it will light up the cell.

  7. #7
    Registered User
    Join Date
    02-20-2009
    Location
    bristol, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: subtracting 2 columns of data from each other when labels in separate columns mat

    Perfect, once again, my thanks for all your help with this.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: subtracting 2 columns of data from each other when labels in separate columns mat

    Glad to help.

    If that takes care of your need, be sure to EDIT your original post (Go Advanced) and mark the PREFIX box [SOLVED]

  9. #9
    Registered User
    Join Date
    09-18-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: subtracting 2 columns of data from each other when labels in separate columns match

    Bump. I am trying to use this exact same formula. I have 4 colums.

    S=ID T= Value, U=ID, V=Value

    I need to create a forumula that if U=S then subtract V from T.

    I am presently using the forumla: =IF(ISERROR(MATCH(U3,$S$3:$S$2972,0)),"",T3-INDEX($V$3:$V$2972,MATCH(U3,$S$3:$S$2972,0)))

    and starting at places where a U does not = a S then it gives me random numbers.

    To clarify this, there are 2972 S's, and only 2112 U's. So What I need my forumula to do is where there is not a coresponding S then just move to the next calculation. I need a Value for every U all the way down.

    Sample Data:

    S T U V

    470 4169 10,548 470 4169 4,015
    470 4127 10,828 470 4127 9,554
    470 5474 118,461 470 5474 117,392
    470 4830 2,473 470 4830 942
    470 4170 10,548 470 4170 4,015
    470 4196 79,019 470 4196 31,428
    470 15034 788,488 470 4143 1,178
    470 4143 3,096 470 4214 5,849
    470 4214 14,706 470 4144 2,356

    There will be a value for every S, and when there is a value for every S I need this formula to find the corresponding value in V then subtract that the value of the corresponding T. S and U are product id's and T and V are volumes, I just need to know what volumes changed.

  10. #10
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: subtracting 2 columns of data from each other when labels in separate columns match

    Hello Black Car 10, and welcome to the forum.

    Unfortunately you have inadvertently broken one of the forum rules. Please read the following and make the necessary change. Thanks.

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

+ 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