+ Reply to Thread
Results 1 to 16 of 16

Return a value as output based on first 5 columns

  1. #1
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Return a value as output based on first 5 columns

    Hi,

    I have a spreadsheet attached that contains information in the first 5 columns as follows:

    Date
    Location
    R
    Type
    R T

    I need to return a number for each unique value, I have inserted a column with values in the attached in Col F as what I am trying to achieve.

    Essentially, if the date, location, R and R T are the same (type does not matter at this stage), then it should return a number starting from 1 and increasing by 1 each time.

    My sheet has many rows, with multiple dates, locations, R, Types and R T's, but attached is only a sample.

    Hopefully this has explained what I am looking for, but if not please let me know.

    I tried using SUMPRODUCT but could not get the desired result.
    Attached Files Attached Files

  2. #2
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,368

    Re: Return a value as output based on first 5 columns

    Typed on F2 and copied down as necessary

    =IF(COUNTIF(E$2:E2,E2)=1,MAX(F$1:F1)+1,VLOOKUP(E2,E1:F$2,2,0))

  3. #3
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Return a value as output based on first 5 columns

    hi there. this could slow down your workbook a fair bit. try it in cell F2
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  4. #4
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Return a value as output based on first 5 columns

    thanks azumi, but when I add a new row with a different location and same R T, it goes back to 1. I need this number to continue to increase so should return 5. I have shown in the attached by adding data to row 71.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Return a value as output based on first 5 columns

    Quote Originally Posted by benishiryo View Post
    hi there. this could slow down your workbook a fair bit. try it in cell F2
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
    Thanks benishiryo, yes it works but unfortunately when I copy it down 30,000 rows, it crashes Excel on my machine, so you are right in saying it would slow down my workbook

  6. #6
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,368

    Re: Return a value as output based on first 5 columns

    Perhaps, put this on F2 and copied down, i use column C and D as guidelines

    =IF(COUNTIFS(C$2:C2,C2,E$2:E2,E2)=1,MAX(F$1:F1)+1,VLOOKUP(E1,E1:F1,2,0))

  7. #7
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Return a value as output based on first 5 columns

    Thanks again azumi, but this does not provide the correct result in my master spreadsheet with 30,000+ rows. I think that when the cat is the same as the cat above (even though it is a different date and location, it returns the same as the previous value

  8. #8
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Return a value as output based on first 5 columns

    maym please upload a more representative workbook (layout and mix) of what you are describing and the expected results. It doesn't have to be large. 5-8 rows of each mix.

    I get same results as above with my formulas, but I see mine will also have the same problems.

    Edited In the meantime try this.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by FlameRetired; 10-31-2017 at 10:08 PM.
    Dave

  9. #9
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Return a value as output based on first 5 columns

    thanks FlameRetired. Your formula works, and here is a more comprehensive workbook.

    However I have the same problem when it calculates (it crashes Excel on my PC) ??
    Attached Files Attached Files

  10. #10
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Return a value as output based on first 5 columns

    That is very strange. As formulas go that one is a "light weight".

    Do you have any other formulas with a large number of volatile functions (OFFSET, INDIRECT, TODAY, NOW ...) or a large number of array formulas ... whole column/row references calculating in other open workbooks?

    Have you tried closing Excel and starting up again?
    Last edited by FlameRetired; 10-31-2017 at 10:47 PM.

  11. #11
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Return a value as output based on first 5 columns

    Hi FlameRetired

    yes, I closed Excel and started again and all fine now

    One further question, if I have a label in row 1 as a header, and my formula starts in row 2, how can I adjust accordingly (as currently returns a #VALUE! error).

  12. #12
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Return a value as output based on first 5 columns

    Good deal. For the #VALUE errors, wrapping the N function around text references takes care of that. It returns 0 with references to text.

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

  13. #13
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Return a value as output based on first 5 columns

    perfect, thanks FlameRetired

    Now, if I wanted to count each of these instances in a pivot table (or otherwise), how can I achieve this? I have shown in the attached example, but essentially if I wanted to count all of the Cat 1's in RT, there would actually only be one of these (as the date, location, and R T are the same) and so on.
    Attached Files Attached Files

  14. #14
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Return a value as output based on first 5 columns

    Please check Cat 112. I believe that should be a 1. I can get the other numbers by formula, but had to expand the source data with a Unique RT counter in column G.

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

  15. #15
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Return a value as output based on first 5 columns

    brilliant, thank you!

    Cat 112 is definitely 2, as it has 2 instances of R. I have included the column with R and it now works

    Please Login or Register  to view this content.

  16. #16
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Return a value as output based on first 5 columns

    Good deal. You are welcome. Thank you for the feedback.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Replies: 1
    Last Post: 01-16-2017, 03:07 PM
  2. Replies: 2
    Last Post: 05-07-2015, 04:38 PM
  3. Replies: 1
    Last Post: 02-02-2015, 11:31 AM
  4. Lookup 2 columns and return value based on another 2 columns
    By rlsublime in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2012, 11:16 AM
  5. Replies: 6
    Last Post: 01-09-2012, 03:34 PM
  6. Looping through columns to copy output into other sheet, and saving output
    By eludlow in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-08-2009, 06:27 AM
  7. Removing Duplicates based on two Columns, Output results to new Spreadsheet
    By crush in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2009, 02:26 PM

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