+ Reply to Thread
Results 1 to 12 of 12

Can anyone please improve my formula?

  1. #1
    Registered User
    Join Date
    06-29-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Can anyone please improve my formula?

    Hi,

    I was wondering if anyone could suggest an improvement to my formula?

    I know its long (sorry) but it works. I have 3000 cells populated with it at the moment, here it is:


    =IF(Y$5="NONE","",IF($W10<=$V$6,IF(D$2="CHANGE IN SITUATION",((IF($M$2="Days",SUMIF(TransactionDate,"=" & $X10,TransAmount),IF($M$2="Months",SUMIFS(TransAmount,TransactionDate,"<=" & EOMONTH($X10,0), TransactionDate, ">=" & (EOMONTH($X10,-1)+1)),IF($M$2="Years",SUMIFS(TransAmount,Year_Transaction,"=" & $X10)))))),IF(D$2="OVERALL SITUATION",(('Account Expenditure'!$L$23)+IF($M$2="Days",SUMIF(TransactionDate,"<=" & $X10,TransAmount),IF($M$2="Months",SUMIFS(TransAmount,TransactionDate,"<="&(EOMONTH($X10,0))),IF($M$2="Years",SUMIFS(TransAmount,Year_Transaction,"<=" & $X10))))),IF($F$3="Balance",(IF(D$2=$T$55,'Account Expenditure'!$L$8,IF(D$2=$T$56,'Account Expenditure'!$L$9,IF(D$2=$T$57,'Account Expenditure'!$L$10,IF(D$2=$T$58,'Account Expenditure'!$L$11,IF(D$2=$T$59,'Account Expenditure'!$L$12,IF(D$2=$T$60,'Account Expenditure'!$L$13,IF(D$2=$T$61,'Account Expenditure'!$L$14,IF(D$2=$T$62,'Account Expenditure'!$L$15,IF(D$2=$T$63,'Account Expenditure'!$L$16,IF(D$2=$T$64,'Account Expenditure'!$L$17,IF(D$2=$T$65,'Account Expenditure'!$L$18,IF(D$2=$T$66,'Account Expenditure'!$L$19,IF(D$2=$T$67,'Account Expenditure'!$L$20,IF(D$2=$T$68,'Account Expenditure'!$L$21,IF(D$2=$T$69,'Account Expenditure'!$L$22)))))))))))))))+IF($M$2="Days",SUMIFS(TransAmount,TransactionDate,"<=" & $X10,TransAccount,"=" & D$2),IF($M$2="Months",SUMIFS(TransAmount,TransactionDate,"<=" & $X11-1,TransAccount,"=" & D$2),IF($M$2="Years",SUMIFS(TransAmount,Year_Transaction,"<=" & $X10,TransAccount,"=" & D$2))))),IF($D$3="Catagory",IF($M$2="Days",SUMIFS(TransAmount,TransactionDate,"="&($X10),TransType,"<>"& IF($E$3="DD / SO","Manual",IF($E$3="Manual","DD / SO","All")),TransCatagory,"="&D$2,TransAmount,IF($F$3="Expenditure","<"&0,IF($F$3="Income",">"&0,IF($F$3="Cashflow","<>"&0)))),IF($M$2="Months",SUMIFS(TransAmount,TransactionDate,"<="&(EOMONTH($X10,0)),TransactionDate,">"&(EOMONTH($X10,-1)),TransType,"<>"& IF($E$3="DD / SO","Manual",IF($E$3="Manual","DD / SO","All")),TransCatagory,"="&D$2,TransAmount,IF($F$3="Expenditure","<"&0,IF($F$3="Income",">"&0,IF($F$3="Cashflow","<>"&0)))),IF($M$2="Years",SUMIFS(TransAmount,Year_Transaction,"=" & $X10,TransType,"<>"& IF($E$3="DD / SO","Manual",IF($E$3="Manual","DD / SO","All")),TransCatagory,"="&D$2,TransAmount,IF($F$3="Expenditure","<"&0,IF($F$3="Income",">"&0,IF($F$3="Cashflow","<>"&0))))))),IF($M$2="Days",SUMIFS(TransAmount,TransactionDate,"="&($X10),TransType,"<>"& IF($E$3="DD / SO","Manual",IF($E$3="Manual","DD / SO","All")),TransAccount,"="&D$2,TransAmount,IF($F$3="Expenditure","<"&0,IF($F$3="Income",">="&0,IF($F$3="Cashflow","<>"&0)))),IF($M$2="Months",SUMIFS(TransAmount,TransactionDate,"<="&(EOMONTH($X10,0)),TransactionDate,">"&(EOMONTH($X10,-1)),TransType,"<>"& IF($E$3="DD / SO","Manual",IF($E$3="Manual","DD / SO","All")),TransAccount,"="&D$2,TransAmount,IF($F$3="Expenditure","<"&0,IF($F$3="Income",">"&0,IF($F$3="Cashflow","<>"&0)))),IF($M$2="Years",SUMIFS(TransAmount,Year_Transaction,"=" & $X10,TransType,"<>"& IF($E$3="DD / SO","Manual",IF($E$3="Manual","DD / SO","All")),TransAccount,"="&D$2,TransAmount,IF($F$3="Expenditure","<"&0,IF($F$3="Income",">"&0,IF($F$3="Cashflow","<>"&0))))))))))),""))



    Thank you in advance...

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Can anyone please improve my formula?

    best you post the workbook! and explain what is supposed to be happening!
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Can anyone please improve my formula?

    I have to say, that formula is just nuts.

    It is not auditable, it is not maintainable, and if you have 3000 with that formula in, it is trance-inducing.

    You have to re-design, use helper cells, use UDFs, use anything but get rid of it.

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Can anyone please improve my formula?

    BTW, it also errors when I try to add it to a worksheet, and I don't have the skill or the patience to debug why - as I said it is not maintainable.

  5. #5
    Registered User
    Join Date
    06-29-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Can anyone please improve my formula?

    Thanks for your replies.

    Sorry its nuts, I thought it was too but it was the only way so far I could get what I wanted without 20 different cells doing 20 different things and summing them all out - leading to about 60000 populated cells.

    I will have to work on the workbook and then get it uploaded somewhere as it is 3.2MB with all of the other formulas and I will have to delete all of the sensitive values first and cut it down / put dummy values in.

    It does not throw errors on my worksheet but I did spend a long time writing / debugging / adding to it.

    Essentially it is intended on displaying different values and sums on demand of an end user selecting different perameters so that the graph on the sheet is truely dynamic.

    I.e. the user can choose different accounts, types of expenditure, income, balances and cashflow over varying time periods and intervals and the graph changes to suit.

    I will try to post it another day once I have had time to cut it down,

    Thanks again.

  6. #6
    Registered User
    Join Date
    06-29-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Can anyone please improve my formula?

    Oh and I assume helper cells are for intermediate steps, please, what are UDFs?

  7. #7
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Can anyone please improve my formula?

    UDFs are User Defined Functions. You can have a UDF that is called from a workheet formula and it can do many things, for instance if you have a test being repeated within your overall formual, you can write it in a UDF and simplify the formula by calling the UDF each time rather than repeating the complex functions.

    But this is all conjecture, the correct answer, or more probably a GOOD answer, can only be given knowing what the business requirement(s) is(are), and what constraints are imposed. The best solution is then teh simplest design that gives the corerct answer, maybe helper cells, maybe UDFs, maybe pivot tables, who knows.

  8. #8
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Can anyone please improve my formula?

    UDF is a User Defined Function. It uses Visual basic but is inputted into a cell just like any other function ie. in C5 =MyFunction(A1:A7). The code is typically stored in a module just like a macro would be.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

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

  9. #9
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Can anyone please improve my formula?

    Quote Originally Posted by B00105904 View Post
    Sorry its nuts, I thought it was too but it was the only way so far I could get what I wanted without 20 different cells doing 20 different things and summing them all out - leading to about 60000 populated cells.
    Whilst I think you need something far more radical than a few helper cells, it is more than likely than 60,000 simpler cells will be better in maintainability and in performance than 3,000 complex cells. This is because of the way the Excel calculation engine works.

  10. #10
    Registered User
    Join Date
    06-29-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Can anyone please improve my formula?

    Thanks,

    I tried pivot tables but they did not give the required result, or I could not get them to, not in the way I wanted.
    The helper cells would have helped debugging I suppose but they would have been 60k+ lol
    I shall try as you have advised and read up on UDFs... thanks!

  11. #11
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Can anyone please improve my formula?

    Quote Originally Posted by B00105904 View Post
    Thanks,

    I tried pivot tables but they did not give the required result, or I could not get them to, not in the way I wanted.
    The helper cells would have helped debugging I suppose but they would have been 60k+ lol
    I shall try as you have advised and read up on UDFs... thanks!
    As I said, 60,000 will probably be better than 3,000 in all ways.

  12. #12
    Registered User
    Join Date
    06-29-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Can anyone please improve my formula?

    Quote Originally Posted by Bob Phillips View Post
    ...it is more than likely than 60,000 simpler cells will be better in maintainability and in performance than 3,000 complex cells. This is because of the way the Excel calculation engine works.
    Oh I had not known this, it might explain my performance issues I was having on lesser powered PCs, interesting.

    I now wonder how hard it will be for me to break down the working if vulgar solution I have

+ 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