+ Reply to Thread
Results 1 to 16 of 16

How to calculate max profit per quarter ?

  1. #1
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412

    How to calculate max profit per quarter ?

    Looking for a Formula to get the Quarter number for the highest profit per Product, like in B16:F16.
    The excersiser instracted us that it must be with one formula with no Macro, not User Defined Function and not openning additional colums.
    I know how to find the qtr. Number - like for A2: =INT((MONTH(A2)+2)/3) but I am lost in finding how to combine the calculation for the Qtr and the most profitable Qtr. probably with MAX on SUM.
    Thank you all in advance,
    Elm
    Attached Files Attached Files
    Last edited by ElmerS; 11-28-2008 at 08:09 PM.

  2. #2
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Find Max Quarter

    HI

    I have added formulas to calculate what you are looking for using a combination of nested IF, Sum and Max.

    Unfortunately it gives quite a long formula, however it is quite straightforward, but if you have any questions please let me know.

    Regards

    Jeff
    Attached Files Attached Files

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    I'm a big fan of naming ranges of cells to make formulas easier to read.

    Name the cells for Product A Quarter 1 PAQ1 by highlighting them and typing PAQ1 into the Name Box. Repeat for the other three quarters...PAQ2, PAQ3, and PAQ4.

    Now, in cell B16, the following formula will identify the most profitable quarter:
    Please Login or Register  to view this content.
    The same code without the named ranges:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 11-28-2008 at 06:53 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412
    Thank you very much, but as you said it is quite a long formula and I with your permission I will for more replies maybe someone will find a shorter solution with an Array Formula or similar.

    edit:
    this was posted to Jeff.

  5. #5
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412
    Thank you JBeaucaire, but when I copy the formula from B16 to C16 it returns 2 instead of 1.

    The same result [2] is returned in D16, E16 and F16.

    What did I do wrong?

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Nothing, I just interpolated my formula into yours and it worked for the first column, I didn't copy it across to see the logic error.

    You're right, an array is needed for a short formula, which I'm less proficient at. However, this formula in B16 works, ugly, but copies across smoothly:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412
    yes, this one works fine but I am sure our instructor did not mean such a long formula.
    Jeffs formula is also a little too long but is shorter than yours.
    I am sure it can be solved, maybe an array formula.
    I saw once an array formula making use of ROW(INDIRECT combined with MOD but cannot find it now.
    I will wait for more suggestions.
    Thanks again,
    Elm

  8. #8
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    In my mind, this is an obvious way of doing it:
    =MATCH(MAX(SUM(B2:B4),SUM(B5:B7),SUM(B8:B10),SUM(B11:B13)),{SUM(B2:B4),SUM(B5:B7),SUM(B8:B10),SUM(B11:B13)},0)

    unfortunately, I can not make Excel accept this formula - I'm wondering if it's because I'm trying 2007 for the first time, or whether I'm being a big fat thicky...

  9. #9
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412
    Thanks, but this does not work in Excel 2003 either.
    Sometimes you get a good idea but the hard part is to translate it into "Excel"s language.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    In B16 and copy across,

    =MATCH(MAX(SUBTOTAL(9, OFFSET(B1, {1,4,7,10}, 0, 3))), SUBTOTAL(9, OFFSET(B1, {1,4,7,10}, 0, 3)), 0)
    Entia non sunt multiplicanda sine necessitate

  11. #11
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    Hey shg, why does subtotal9 work and sum doesn't?

  12. #12
    Forum Contributor
    Join Date
    11-28-2008
    Location
    Reykjavík, Iceland
    MS-Off Ver
    Any of: 2003 & 2007
    Posts
    412
    More than Perfect.

    Thank you.

  13. #13
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by Cheeky Charlie View Post
    Hey shg, why does subtotal9 work and sum doesn't?
    Using OFFSET like that allows you to generate an "array of ranges" which SUBTOTAL can then sum, see here

    You could generate an array of sums with your method by introducing CHOOSE, i.e.

    =MATCH(MAX(CHOOSE({1,2,3,4},SUM(B2:B4),SUM(B5:B7),SUM(B8:B10),SUM(B11:B13))),CHOOSE({1,2,3,4},SUM(B2:B4),SUM(B5:B7),SUM(B8:B10),SUM(B11:B13)),0)

    ....but, obviously, shg's suggestion is more elegant

  14. #14
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    ....but, obviously, shg's suggestion is more elegant
    ...



    yep

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Quote Originally Posted by DLL
    Using OFFSET like that allows you to generate an "array of ranges" which SUBTOTAL can then sum
    I recollect picking up that construct from a recent DLL post.
    Quote Originally Posted by CC
    Hey shg, why does subtotal9 work and sum doesn't?
    Dunno. I sense it's somewhat analogous to the difficulty of using AND and OR in array formulas; they operate on all of their arguments in one go, rather than successively on the elements of an array. Maybe DLL can generalize the issue.
    Last edited by shg; 11-28-2008 at 09:51 PM.

  16. #16
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by shg View Post
    ......I sense it's somewhat analogous to the difficulty of using AND and OR in array formulas; they operate on all of their arguments in one go, rather than successively on the elements of an array. Maybe DLL can generalize the issue.
    The link I posted was supposed to help but perhaps it's not specific enough.

    It implies that the clever part is using OFFSET to generate an "array of ranges". I think that is clever but you still need to be able to do something with them which is where SUBTOTAL comes in.

    If you use SUM with OFFSET then you'd just get a sum of everything which defeats the purpose of creating the separate ranges in the first place. SUBTOTAL is able to operate on each specific range generated by OFFSET and return an array of the results.

    In the link examples SUBTOTAL has a twofold purpose, it can evaluate each range seperately....and it ignores filtered rows, possibly that second property obscures the usefulness of the first which is crucial in that example and here.

    Note: I don't know why it works like that, it just does.......

+ 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