+ Reply to Thread
Results 1 to 4 of 4

Assign + or - to the result of a formula based on the number with highest absolute value?

  1. #1
    Registered User
    Join Date
    04-03-2012
    Location
    Baltimore, Maryland, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Assign + or - to the result of a formula based on the number with highest absolute value?

    Hello, I'm a research scientist analyzing some data for a behavioral task my colleagues and I invented. I've developed an informative metric from the data that I understand and can explain conceptually, and can certainly calculate by hand, but am having difficulty figuring out how to get Excel to do it as a formula. Here's a summary of the problem via example:

    Start with a series of numbers; some will be positive and some negative (for example: 50, -100, 25)
    Determine the absolute range within the series (MAX - MIN); in this case [50] - [-100] = 150
    I'm not sure if it matters, but the particular metric I'm developing then divides that number by 2 (150 / 2 = 75)
    So the final formula = (MAX(series) - MIN (series))/2

    All the steps above work just fine and do what I need; however, the number constituting the final result of that formula must be assigned + or - based on the member of the series with the highest absolute value. In the example above, the result of the formula = 75, which is indeed the absolute range divided by 2, but the final number needs to be -75 because the member of the series with the highest absolute value = -100.

    Obviously hand calculation and visually scanning the data are fine for brainstorming/development, but not a reliable approach for high-throughput data processing, so any insight or advice would be most appreciated!

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Assign + or - to the result of a formula based on the number with highest absolute val

    You can do this with a user defined function.

    Please Login or Register  to view this content.
    Alt F11 to VBA editor. Open a new module (Insert-module). Paste in the above. Alt F11 back to workbook


    Type =GetNumber(F2:F4) into a cell for example.
    Martin

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Assign + or - to the result of a formula based on the number with highest absolute val

    Alternate solution:
    =(MAX(A1:A3)-MIN(A1:A3))/2*IF(INDEX(A1:A3,MATCH(MAX(INDEX(ABS(A1:A3),)),INDEX(ABS(A1:A3),),0))<0,-1,1)

    Shorter version:
    =(MAX(A1:A3)-MIN(A1:A3))/2*IF(SUMPRODUCT((ABS(A1:A3)=MAX(ABS(A1:A3)))*A1:A3)<0,-1,1)
    Last edited by tigeravatar; 04-03-2012 at 12:26 PM.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Registered User
    Join Date
    04-03-2012
    Location
    Baltimore, Maryland, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Assign + or - to the result of a formula based on the number with highest absolute val

    Wow, thank you so much! Clearly the Force is very strong with both of you. I wound up going with tigeravatar's "Alternate solution" (the "Shorter version" didn't seem to work out, not sure why) because it was copy-and-paste. However, thank you mrice for the User Defined Function; I don't have much experience with that approach, so this is an excellent opportunity to get my feet wet and improve my repertoire of Excel skills.

    This was the first time I've ever participated in any online forum, and it's nice to know that there are good people out there in the world who are willing to help a perfect stranger--I'll surely pay it forward. Thanks again...

+ 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