+ Reply to Thread
Results 1 to 20 of 20

Simplifying a max(if-then) equation...

  1. #1
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Simplifying a max(if-then) equation...

    Hello,

    My equation is getting longer every time I need to insert columns, and add them to the equation. Is there a way to make the equation below general? Basically, I need the max of a bunch of cells only if the cell 2 columns away from each, respectively, is not zero:

    ={MAX(IF(M13<>0,K13),IF(P13<>0,N13),IF(S13<>0,Q13),IF(V13<>0,T13),IF(Y13<>0,W13),IF(AB13<>0,Z13),IF(AE13<>0,AC13),IF(AH13<>0,AF13),IF(AK13<>0,AI13),IF(AN13<>0,AL13),IF(AQ13<>0,AO13),IF(AT13<>0,AR13),IF(AW13<>0,AU13),IF(AZ13<>0,AX13),IF(BC13<>0,BA13),IF(BF13<>0,BD13),IF(BI13<>0,BG13),IF(BL13<>0,BJ13),IF(BO13<>0,BM13),IF(BR13<>0,BP13),IF(BU13<>0,BS13),IF(BX13<>0,BV13),IF(CA13<>0,BY13),IF(CD13<>0,CB13),IF(CG13<>0,CE13))}

    Would be nice not to edit this stinker ever again. Maybe searching a range out to the right end of the sheet

    Thanks.

    Dave

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Simplifying a max(if-then) equation...

    Quote Originally Posted by spacely View Post
    this stinker
    Yeah, that is pretty nasty!

    If a cell does contain 0 (or is empty evaluating to 0) does that mean its corresponding cell should not be considered for the max value?

    ={MAX(IF(M13<>0,K13)
    If M13=0 exclude K13 from the max?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Simplifying a max(if-then) equation...

    See if this does what you want...

    Data Range
    K
    L
    M
    N
    O
    P
    Q
    R
    S
    T
    U
    V
    W
    X
    Y
    12
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    13
    39
    0
    81
    73
    59
    59
    8
    16
    28
    15
    14
    15
    16
    81


    This array formula** entered in K16:

    =MAX(IF(MOD(COLUMN(M13:Y13),3)=1,IF(M13:Y13<>0,IF(MOD(COLUMN(K13:W13),3)=2,K13:W13))))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

  4. #4
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Re: Simplifying a max(if-then) equation...

    Yep. If any of those is 0, exclude from max. And your formula works. Not sure how I made sure that the M-Y range starts/ends on a yellow "condition", and the K-W range starts/ends on a "value". I assume it won't work otherwise.

    And if I need to insert columns, no editing. If I need to add columns on the end of the range, small easy edit. No worries.

    Where's your tip cup

    Thanks!

  5. #5
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: Simplifying a max(if-then) equation...

    Or try this ...

    =MAX(IF((M1:Y1="condition")*(M13:Y13<>0),K13:W13,""))

    Enter with Ctrl+Shift+Enter.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Re: Simplifying a max(if-then) equation...

    Interesting. I'll go with the first solution that doesn't require extra text somewhere. I'm liable to forget it's needed and delete it

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Simplifying a max(if-then) equation...

    You're welcome. Thanks for the feedback!

  8. #8
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Re: Simplifying a max(if-then) equation...

    Oh oh, spoke too soon. I needed to move the equation to a new cell (to H13 from H14), and I get a circular reference now. I cannot attach the sample.


  9. #9
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Re: Simplifying a max(if-then) equation...

    Maybe I can describe:

    In H13 I want your: ={MAX(IF(MOD(COLUMN(M13:CG13),3)=1,IF(M13:CG13<>0,IF(MOD(COLUMN(K13:CE13),3)=2,K13:CE13))))}

    In I13 is: =INDIRECT("R"&ROW()&"C"&(MATCH(H13,K13:CG13,0)+COLUMN(J:J)+2),FALSE)

    In J13 is: =INDIRECT("R9"&"C"&(MATCH(H13,K13:CG13,0)+COLUMN(J:J)),FALSE)

    Then comes the data on the same row in K+: "value" then a number then the "condition" we spoke of. Repeating like that.

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Simplifying a max(if-then) equation...

    I don't get a circular reference when I try your formulas.

  11. #11
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Re: Simplifying a max(if-then) equation...

    Can I get this sample sheet to you some way? The attachments button seems not to do anything...

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Simplifying a max(if-then) equation...

    To attach a file to your post...

    Click the Reply button to open the Reply Editor
    Click the Go Advanced button
    Scroll down until you see the Manage Attachments link and click that
    Click the Browse button and select your file
    Click the Open button
    Click the Upload button
    Click the Close Window button
    Click the Submit Reply button

  13. #13
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Re: Simplifying a max(if-then) equation...

    OK, I did upload Book3, but I am not sure it's attached to this post.

    There are links inside, so don't update, and the values should show.

    Trying to put the equation in H14 into cell H13.

    Let me know if you don't see a circular reference message.
    Attached Files Attached Files

  14. #14
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,191

    Re: Simplifying a max(if-then) equation...

    L13 refers to H13 ("h" inL8) so you get circular reference when referencing K13 onwards

  15. #15
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Re: Simplifying a max(if-then) equation...

    I see, and your 2nd solution didn't work when placed there either, since they both refer to the whole range. Not sure what the solution is. I would have thought the Indirect masks the circularity.

  16. #16
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,191

    Re: Simplifying a max(if-then) equation...

    Removed by JT
    Last edited by JohnTopley; 11-27-2016 at 12:45 PM.

  17. #17
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Re: Simplifying a max(if-then) equation...

    Instead of CH I used G13, but still a circular reference because the formula (G/H13) references the range containing formula like in L13, which in turn references G/H13.

  18. #18
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,191

    Re: Simplifying a max(if-then) equation...

    Yes ..... (my error - brain freeze!) the only solution is to use VBA to "hard-code" the result in H13 (or wherever) i.e equivalent to "copy/paste special value"

    OR

    move the "L" columns to be a contiguous set of cells after the "K,M" pairs so the formula does not include the current "L" columns.
    Last edited by JohnTopley; 11-27-2016 at 01:41 PM.

  19. #19
    Registered User
    Join Date
    07-08-2016
    Location
    USA
    MS-Off Ver
    Office 365, Office 2016 for PC & Mac, Office 2013, Office 2011 Mac
    Posts
    80

    Re: Simplifying a max(if-then) equation...

    Hi Spacely,

    I am just throwing out an idea here that I am not super familiar with, but it may help. If you change you the calculations to iterative, then I think you would avoid the circular reference error. Hopefully someone else can better expand on this approach or suggest something better.

    Without a macro:
    file→options→formulas→click enable iterative calculation checkbox
    You would have to manually change it between calculation types each time you open the workbook I believe

    With a macro (see attachment):

    Workbook_Open():
    Please Login or Register  to view this content.
    Workbook_BeforeClose:
    Please Login or Register  to view this content.
    Ignore the circular reference when opening the attachment


    DMG

  20. #20
    Registered User
    Join Date
    09-23-2007
    Posts
    54

    Re: Simplifying a max(if-then) equation...

    Seems the couple macros work to suppress the message. Seems pretty fast, so the circularity must not have confused it too bad. Anything bad about simply keeping the Iterative Calculation on for all books, always?

+ 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: 2
    Last Post: 11-03-2014, 08:04 PM
  2. [SOLVED] dragging an equation but only changing one part of the equation
    By mufan in forum Excel General
    Replies: 7
    Last Post: 04-12-2012, 02:48 PM
  3. Replies: 3
    Last Post: 04-09-2012, 01:36 PM
  4. Replies: 4
    Last Post: 02-02-2012, 10:11 PM
  5. Replies: 3
    Last Post: 03-06-2011, 01:38 PM
  6. [SOLVED] Equation Editor- problem when editing an equation
    By Gaby L. in forum Excel General
    Replies: 0
    Last Post: 09-27-2005, 05:05 PM
  7. excel equation (user defined equation)
    By excel_student in forum Excel General
    Replies: 0
    Last Post: 03-10-2005, 03:59 PM

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