+ Reply to Thread
Results 1 to 7 of 7

Comparing values by category

  1. #1
    Registered User
    Join Date
    03-24-2013
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Comparing values by category

    Need some help here with creating a formula with which to check the if the individual quantities of each type of item is not less than its previous balance.

    I'd like my table to look something like the following:

    Category Initial Count Balance Check
    Type X 100 200 OK
    Type Y 50 80 OK
    Type Z 10 15 OK
    Type X 250 300 OK
    Type Z 18 20 OK
    Type Y 70 90 Error

    Problem is, I don't quite know how to write the formula for the logic check, such that whenever I check the initial count of an item type, it should always be at least equal to or more than the balance of the last occurrence of that item type.
    In the example above, Type Y returns an error in the check, as it starts with 70 the second time, when it ended with a balance of 80.

    I'm guessing I'll need to use an array to do the initial check of matching the categories in the first column to every other one, but I'm not quite sure how to do that.

    Would really appreciate any help here, thanks!

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,967

    Re: Comparing values by category

    Hi and welcome to the forum

    Try this, copied down...

    =IF(COUNTIF($A$2:A2,A2)=1,"",IF(VLOOKUP(A2,$A1:C$2,3,FALSE)>B2,"ERROR","OK"))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    03-24-2013
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Comparing values by category

    Hi, thanks for the welcome and suggestion!

    I'll give that a shot and see if it works. I tried it a bit but it didn't work the first time round, but that might be because the table was a little more complicated than the one I'd illustrated above. Will try to modify the formula provided and hope that works. :P
    Last edited by digitalsilver; 03-25-2013 at 04:53 AM.

  4. #4
    Registered User
    Join Date
    03-24-2013
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Comparing values by category

    Ah ok, just realised why it wasn't working (though I still don't know how to solve it)

    It works great for the second instance of an item type, but once a third row of the same type showed up, it would only compare its count to the balance of the first instance, not any subsequent ones.
    I'm not too familiar with VLOOKUP, but is it because that function only returns the first instance and not any others?

  5. #5
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,915

    Re: Comparing values by category

    =IF(COUNTIF($A$2:$A2,$A2)=1,"OK",IF(INDEX($A$2:$C$7,LARGE(INDEX(($A$2:$A2=$A2)*ROW(INDIRECT(1&":"&ROWS($B$2:$B2))),0),2),3)>B2,"Error","OK"))
    assuming that the data was in "A2:D7". Try the above formula in cell no "D2" and copy the same towards down

  6. #6
    Registered User
    Join Date
    03-24-2013
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Comparing values by category

    Looks like this works, thanks so much, both of you!

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,967

    Re: Comparing values by category

    Happy to help and thanks for the feedback

+ 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