+ Reply to Thread
Results 1 to 7 of 7

Unique Number based on conditions with lookup

  1. #1
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Unique Number based on conditions with lookup

    Hi,

    I require some help with a model I am needing to create. I am trying to create a model which will allow me to dump some data into a spreadsheet and then automate the process of creating a finance journal.

    I have split the requirements into two parts as one feeds the other.

    Unique Number
    The first requirement is for a unique number to be assigned based on two conditions:
    • If there is a cost greater than zero in column CC
    • If there is an entry in column C (a WBS code to recharge to)


    The unique number would need to be in column B of the data sheet

    Lookup based on unique number
    The next part isn’t as easy as it may first appear.

    The way the journal will work is that if there is a cost and a WBS present then it will have to be credited and recharged, I would like to pull this information automatically as it should all be contained on the data sheet. So, for reference, for each cost (as long as it has a WBS to recharge to) then there will be two lines on the journal (one to credit the original and then one to debit the recharge WBS).

    If the data has a cost but no WBS to recharge to then this will not be journaled.

    I have provided an example of what I require and have filled it in as if it was working.

    Can anyone help please with how best to achieve what I need. It doesnt have to be the way I have suggested.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Unique Number based on conditions with lookup

    Hi,

    The first part is relatively easy. In B8 copied down

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    I'll revert back on part 2.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    03-28-2014
    Location
    Hyderabad,India
    MS-Off Ver
    Excel 2013
    Posts
    1,887

    Re: Unique Number based on conditions with lookup

    Hi,

    Find the updated sheet information required in regard of Credit and Debit Amount

    Punnam
    Attached Files Attached Files

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Unique Number based on conditions with lookup

    Hi,

    See attached. I added a copy Journal sheet so that I could check back to the original.
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Re: Unique Number based on conditions with lookup

    Hi,

    Thanks you both for the replies:

    I want to try and understand how this has been achieved as no doubt I will need to modify it slightly with the actual model 9this is dummy data).

    @Richard

    Can you help me try and understand the formulas:

    =INDEX(OFFSET(Data!C:C,0,IF(MOD(ROW(),2)=1,2,0)),MATCH(ROUND(ROW()/2,0)-6,Data!B:B,FALSE),1)

    And

    =INDEX(Data!H:H,MATCH(ROUND(ROW()/2,0)-6,Data!B:B,FALSE),1)

    @Punnam

    What is the helper column (A) doing?

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Unique Number based on conditions with lookup

    Hi,

    =INDEX(OFFSET(Data!C:C,0,IF(MOD(ROW(),2)=1,2,0)),MATCH(ROUND(ROW()/2,0)-6,Data!B:B,FALSE),1)

    This is in column E and it refers to either column C or E on the Data tab, i.e. a choice of two columns. Since the formula needs to be consistent as it's copied down it has to alternate between finding one or other of the two columns C or E. We do this by using Modulus 2 and applying it to the row number. This is the bit of the formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    i.e. it takes the row number, say row 13 and applies Modulo 2 (i.e. it divides 13 by 2 and returns the remainder 1) The same formula on row 14 will return zero.
    This MOD formula is wrapped inside an IF() function so that when the MOD formula equals 1, the IF function gives 2, and if MOD() is NOT 1 IF() gives 0. The point about 2 & 0 is that we can use these as column Offsets from Data column C. i.e. a column Offset of zero from col C us still C, and an Offset of 2 is column E.
    This is where the
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    bit comes in. Offset takes either 3 or 5 arguments. Here we use 3 arguments. The anchor range column C, and then a row and column offset. Here the ,0 is a row offset of zero, and the column Offset is either 0 or 2 from the IF(MOD()) formula.

    This OFFSET formula now forms the first part of an INDEX() function. INDEX takes three terms. A Range, a row in that range, a column in that range. So here the Index Range is either Data column C or E depending on what the Offset returns. The final bit is the MATCH() function which tells us the row number in the Index Range. MATCH() has three elements, a value, a range, and a parameter which dictates whether an EXACT match needs to be found or a value which is nearest to the required value.

    ROUND(ROW()/2,0) gives the value to be matched. If this is on row 13, then 13/2 when rounded gives 7. On row 14, 14/2 also gives 7. On row 15, 15/2 rounded gives 2. So you can see that every two rows will be the same and successive groups of 2 rows will increment by 1. Since we start on row 13 which results in 7, when we deduct the constant 6 then we get the result 1. on row15 we get 2, on row 17, 3 etc...) SO now we have the series 1,2,3, which are used as the values to match in data column B which are also numbered 1,2,3. So a MATCH function on row 13 of the journal sheet will look for value 1 in column B on the Data sheet and return the value 8 since that's the row that has the value 1.

    So now we have the second part of the Index() function which is the row element, the last part of the Index() function is the constant 1. So now the whole of the INDEX() function gives us either Data Column C or E, row 8, column 1.

    Hope that helps. The shorter formula is similar and uses the same technique so hopefully you can apply the above explanation to it.

  7. #7
    Forum Expert
    Join Date
    03-28-2014
    Location
    Hyderabad,India
    MS-Off Ver
    Excel 2013
    Posts
    1,887

    Re: Unique Number based on conditions with lookup

    Hi
    Column A=IF(AND(CC8>0,C8<>""),VALUE(TRIM(RIGHT(C8,2))),"") just a if condition to satisfy the first requirement
    1) if there is a cost greater than zero in column CC 2)If there is an entry in column C (a WBS code to recharge to)
    and the =IF(A8="","",COUNTIF($A$8:A8,">="&1)) in column B is counting greater than Zero and give the sequence of number from 1 ,2,3,4,5....

    Punnam

+ 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. [SOLVED] A lookup function based on two criteria; one unique & one not unique to the lookup table
    By Trevasaurus in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-18-2014, 11:35 AM
  2. Replies: 13
    Last Post: 12-19-2012, 02:38 PM
  3. Assign a unique number if conditions are met
    By SomDai in forum Excel General
    Replies: 8
    Last Post: 10-04-2012, 03:25 PM
  4. [SOLVED] count the number of unique values given certain conditions
    By eh308701 in forum Excel General
    Replies: 8
    Last Post: 05-31-2012, 11:48 PM
  5. Lookup Unique based on Multiple Conditions
    By statenja in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-05-2009, 09:31 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