+ Reply to Thread
Results 1 to 10 of 10

Formula to pick up max value and apply that max record values to other recordswith same ID

  1. #1
    Registered User
    Join Date
    03-15-2020
    Location
    Sydney, Australia
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    20

    Formula to pick up max value and apply that max record values to other recordswith same ID

    Hi All,

    I'm need of a generalised formula for many such attributes with many records

    I have two records, with three columns
    A1: Base B1: Attribute 1 C1: Attribute 2
    A2: 766786 B2: 2 C2: 3
    A3:766786 B3: 3 C3: 2

    I want a fourth and fifth column with the following logic:

    1. Check for the data in row 2 and 3 for each of the Attribute 1 and Attribute 2, i.e. B2 against B3 and C2 against C3
    2. If the data is same, then for both the Base records pick one of the record from the two and fourth column will have the Attribute 1 data and fifth column will have Attribute 2 data
    3. If the data is not same, then check for Attribute 1 column and pick the max of the value and assign the associated max value record to column four and five, ie. as per the above example fourth column will have 3 and fifth column will have 2 as this is the max value associated record
    4. IF the data is not same and the Attribute 1 data is same, then check for Attribute 2 column and pick the max of the value and assign the associated max value record to column four and five
    5. Similarly this formula should carry out for any number of attributes and perform the checks as explained in 2, 3 and 4
    Attached Files Attached Files
    Last edited by Snehith Moturi; 07-24-2023 at 08:51 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,882

    Re: Formula to pick up max value and apply that max record values to other recordswith sam

    There are instructions at the top of the page explaining how to attach your sample workbook (yellow banner: HOW TO ATTACH YOUR SAMPLE WORKBOOK). Screenshots are of little practical use as we cannot manipulate them.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, worked examples where required, relevant cells highlighted and a few explanatory notes.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    03-15-2020
    Location
    Sydney, Australia
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    20

    Re: Formula to pick up max value and apply that max record values to other recordswith sam

    Hi all,

    I have attached a sample workbook as a reference with the expected output. Please help look into it and suggest me the formula.

    Thanks!
    Snehith

  4. #4
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Formula to pick up max value and apply that max record values to other recordswith sam

    This formula returns the requested output, but does not repeat:

    Please try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Is this also sufficient? Or should the output be repeated for every time the base also repeats?
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    03-15-2020
    Location
    Sydney, Australia
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    20

    Re: Formula to pick up max value and apply that max record values to other recordswith sam

    Hi Hans,

    Thanks for your inputs.

    I was expecting the output to be repeated for each of the Base. Also, can you please elaborate the formula I'm not aware of the functions (HSTACK, LAMBDA,VSTACK,TAKE) that you have used.

    Appreciate if you can explain these functions and if possible can you please share an alternative approach so that it's easily understood and applied in other use cases as well.

    Thanks!
    Snehith

  6. #6
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Formula to pick up max value and apply that max record values to other recordswith sam

    LET(b,A2:A17,...): Name the range A2:A17 with the bases b

    FILTER(b,b): Ignore empty values

    u,UNIQUE(FILTER(b,b)): Determine the unique values ​​of the bases and call them u

    REDUCE("",u,LAMBDA(i,v: Perform a certain operation per unique base and an initial value and after each operation replace the initial value with the result of that operation.
    The initial value is an empty value the first time and is called i in the formula with the operation, and the base is called v in the formula with the operation.

    VSTACK(i,TAKE(SORT(FILTER(B2:D17,b=v),{1,2,3}),-1)):This is the third parameter of the LAMBDA function and contains the operation to be repeated for each unique base:

    FILTER(B2:D17,b=v): Select all rows with attributes belonging to a particular base
    SORT(...,{1,2,3}): Sort them in ascending order by Attribute 1, within that by attribute 2, and within that by attribute 3.
    TAKE(...,-1): And take the last (bottum) row of that
    VSTACK(i,....): Place that row below the initial value and set the result as the new initial value

    Then repeat the steps above for each unique base

    DROP (....,1): Remove the first row from the final result so far. That's the first initial value with the empty cell I started with.

    HSTACK(u,....): Place the column with the unique bases and the final result obtained from the REDUCE LAMBDA function next to each other.

  7. #7
    Forum Contributor
    Join Date
    10-22-2022
    Location
    Santa Cruz, Bolivia
    MS-Off Ver
    MSO 365
    Posts
    146

    Re: Formula to pick up max value and apply that max record values to other recordswith sam

    hi there, after check the consult I allow to propose another possible solution:

    Please Login or Register  to view this content.
    I hope it results useful.

    Test (Solution).xlsx
    Last edited by ExceLogan; 07-24-2023 at 10:48 AM.

  8. #8
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Formula to pick up max value and apply that max record values to other recordswith sam

    Very nice ExeLogan.

    Here's another formula that repeats results for every occurrence of a base.

    This is a copy down formula: Try in A2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    10-22-2022
    Location
    Santa Cruz, Bolivia
    MS-Off Ver
    MSO 365
    Posts
    146

    Re: Formula to pick up max value and apply that max record values to other recordswith sam

    That's good one too HansDouwe, the only thing I can see its the hard code {1,2,3} need to be adjusted everytime the data increase the number of attributes, as mentioned in point 5 of the consult:

    5. Similarly this formula should carry out for any number of attributes and perform the checks as explained in 2, 3 and 4

  10. #10
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Formula to pick up max value and apply that max record values to other recordswith sam

    Yes your formula is neater ExceLogan. I will study your formula and learn from it. Thanks.

    You also bypassed the SORT nicely, but I was a bit lazy.

    Tomorrow I will think about passing the SORT in a different way.

+ 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] Formula(s) to Pick Up Unique Values From Each Row
    By Taisir in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-15-2018, 07:54 AM
  2. Pick the earliest date for a record from a row of those records?
    By misterGwhizz in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-30-2014, 02:01 PM
  3. Replies: 3
    Last Post: 02-04-2014, 11:38 AM
  4. [SOLVED] Changing range on formula will not allow me to pick up values
    By levtweeney in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-21-2013, 03:05 AM
  5. [SOLVED] Pick a record from a list then sum the values attributable to it
    By ChrisMTrigg in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-12-2012, 06:46 AM
  6. Replies: 1
    Last Post: 06-11-2008, 04:06 PM
  7. Formula to pick out number values
    By JaneC in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-09-2006, 09:30 AM

Tags for this Thread

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