+ Reply to Thread
Results 1 to 25 of 25

Nested IF functions

  1. #1
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Nested IF functions

    Hi all

    New member here and am hoping someone can help me a nested if function, or a better function for my problem.

    I have a drug that is taken with a 16 day half life, therefore total life of the drug is 32 days. If 400mg taken on day one, 12.5mg will be released daily for the next 32 days. Then 400mg taken on day 3 another 12.5mg will be released from that date and so on.

    For this I have a used a simple if function of =if(C2="x",D2/32,0) with this data set.



    The problem I have is that at the end of the 32 days, I need to trend the values down, so the 12.5mg of the 400mg dose from day 1 will be deducted from the concentration column after 32 days/count, and then the 12.5mg from the 400mg day 3 dose will be deducted from the concentration after 32 count from day 3 and so on.

    Idea is for the blood concentrations of the different doses will be added together over the next 32 days, but after the 32 days will then stop being as the life of the drug is up.

    I'm sure a count function of some sort needs to be used in a nested if formula, but can't come up with something that works.

    Would appreciate any help

    Thanks

    Ryan
    Last edited by RyanF; 06-18-2009 at 07:26 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Nested IF functions

    I think it would be better if you actually posted a sample worksheet so that we can see where there may be blank cells, etc... in your table...

    Also, please provided samples of expected results.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Quote Originally Posted by NBVC View Post
    I think it would be better if you actually posted a sample worksheet so that we can see where there may be blank cells, etc... in your table...

    Also, please provided samples of expected results.


    I have embedded the spreadsheet in a word doc as the spreadsheet doesn't seem to attach.
    Colum is the formula I have inserted. From day 33 I need the initial dose to stop being added, then the second 400mg (12.5mg) to stop being added from days 35 etc

    Thanks
    Ryan
    Attached Files Attached Files

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Nested IF functions

    So what are the actual expected results in E33 onwards?

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Nested IF functions

    And are there still going to be inputs in columns C and D?

  6. #6
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Quote Originally Posted by NBVC View Post
    And are there still going to be inputs in columns C and D?
    I've coloured the column in yellow which the expected values are. Above the yellow the if formula is calculating the values correctly, but after the yellow starts I need a formula that will reduce the value by 12.5 every second day (to correspond with the end of the life of that dose in the blood).

    After day 32 there will be no more values in column c and d as there will be no more dosing with the drug. The drug will then exit the blood stream based on the life, 32 days, so each initial dose will no longer release 12.5 into the blood stream after 32 days from that dose.
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: Nested IF functions

    Try this in cell E2:

    Please Login or Register  to view this content.
    Copy down as appropriate
    Excel 365 user. To unblock a downloaded macro-enabled workbook, go to your "Downloads" folder > right click on the workbook name > click 'Properties' > check the 'Unblock' checkbox. You can now open the workbook.

  8. #8
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2007, 2010
    Posts
    470

    Re: Nested IF functions

    an alternative - try the following formulas:
    at E2:
    =(C3="x")*D3/32

    at E3:
    =IF(B3<=32,(C3="x")*D3/32,-12.5*(MOD(B3,2)=1))+E2
    copy down for E4:E...
    Last edited by tigertiger; 06-16-2009 at 10:06 AM.

  9. #9
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Nested IF functions

    If you can insert a row above your table, so that Row 1 is blank,

    Then in E3:

    Please Login or Register  to view this content.
    copied down

  10. #10
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Quote Originally Posted by deadlyduck View Post
    Try this in cell E2:

    Please Login or Register  to view this content.
    Copy down as appropriate
    Thanks-appreciate the feedback.

    I'm finding that if I change the value from 400 to 500 in column D, I no longer get the correct figures.
    I'm not sure how the MOD function works or the negative ROW function.

    Appreciate any explanation on this.

    Thanks

    Ryan

  11. #11
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Quote Originally Posted by tigertiger View Post
    an alternative - try the following formulas:
    at E2:
    =(C3="x")*D3/32

    at E3:
    =IF(B3<=32,(C3="x")*D3/32,-12.5*(MOD(B3,2)=1))+E2
    copy down for E4:E...
    This seems to work, even if I change values, but I would appreciate an explanation on the MOD function as I am unfamliliar with this.

    Appreciate the help

  12. #12
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: Nested IF functions

    I'm finding that if I change the value from 400 to 500 in column D, I no longer get the correct figures.
    I'm not sure how the MOD function works or the negative ROW function.

    Appreciate any explanation on this.
    If you need the formula to work for different drugs or half-life durations the formula would need to be modified to allow for the revised concentration (ie dose/full life). If required, I can do this but as you've got the other formula working it may not be needed.

    The MOD(number, divisor) function calculates the remainder of 'number' when divided by 'divisor' eg MOD(10,4) would be 2.

    The ROW() function tells Excel the number of the row you are currently on. It's a useful way to perform computations based on 'how far down your formula has gone'.

    Hope this helps.

    Please ensure that if you are happy with the answer that you mark your original thread as solved.

  13. #13
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Nested IF functions

    I don't know how I copy/paste deadlyduck's formula in my post... but I meant to post this formula: ...ooops.

    Please Login or Register  to view this content.
    after inserting a blank row above the table.

  14. #14
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: Nested IF functions

    I don't know how I copied/pasted deadlyduck's formula in my post...
    ... I was trying to figure out why an extra row was needed for my formula but as it was one of the ExcelForum gurus who suggested it I decided there had to be a reason but was stumped if I could figure it out!

    Thanks for clearing that up!

  15. #15
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Quote Originally Posted by deadlyduck View Post
    If you need the formula to work for different drugs or half-life durations the formula would need to be modified to allow for the revised concentration (ie dose/full life). If required, I can do this but as you've got the other formula working it may not be needed.

    The MOD(number, divisor) function calculates the remainder of 'number' when divided by 'divisor' eg MOD(10,4) would be 2.

    The ROW() function tells Excel the number of the row you are currently on. It's a useful way to perform computations based on 'how far down your formula has gone'.

    Hope this helps.

    Please ensure that if you are happy with the answer that you mark your original thread as solved.

    Thanks-will do.


    =IF(ROWS($D$3:D7)<=32,SUM($D$3:D7)/32,IF(MOD(ROW(),2)=1,SUM($D$3:D7)/32-((ROW()-33)/2)*12.5,E8))

    I'm not clear on what you are doing in the green part of the formula.

    I would appreciate a formula I could use similar to this to with adjusted drug life's and amounts, so I don't have to use an "X" to annotate the drug use on a particular day.
    I would like to try have two cells somewhere on the sheet that the drug life and dose can be inputed into that would change the calcs. or use the days.

    Appreciate the help

  16. #16
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Quote Originally Posted by NBVC View Post
    I don't know how I copy/paste deadlyduck's formula in my post... but I meant to post this formula: ...ooops.

    Please Login or Register  to view this content.
    after inserting a blank row above the table.

    Thanks-will try this as well.

    Appreciate the help all-looking at this I guess I have a lot more excel reading to do

  17. #17
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Nested IF functions

    Quote Originally Posted by RyanF View Post

    I would appreciate a formula I could use similar to this to with adjusted drug life's and amounts, so I don't have to use an "X" to annotate the drug use on a particular day.
    I would like to try have two cells somewhere on the sheet that the drug life and dose can be inputed into that would change the calcs. or use the days.

    Appreciate the help
    Using my solution.. see attached...

    You can enter a Half-Life in H2 and a Dosage in I2 and then amend formula in E2 to:

    Please Login or Register  to view this content.
    and copy down...
    Attached Files Attached Files

  18. #18
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: Nested IF functions

    In the green part of the formula, I was doing the following:
    1. As your first dose was in row 2 and the full life was 32 days, I knew that the row in which the first dose would expire was going to be in row 33
    2. Therefore, I needed to start deducting the daily concentration of that first dose (and subsequent doses) from row 33 onwards.
    3. Each subsequent dose expired in row 35,37,39 etc
    4. So I used the MOD(row(),2) function to identify whether or not a dose expired
    5. I could then deduct the relevant quantities of doses from the total

    that's the basic idea.

    To facilitate variable strengths and concentrations, I need to use a more generalised formula- I am working on that at the moment but may be a while before I get it sorted. You might need to check back later.

  19. #19
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2007, 2010
    Posts
    470

    Re: Nested IF functions

    why don't you use the short formula:

    =E2+IF(B3<=32,(C3="x")*D3/32,-12.5*(MOD(B3,2)=1))

    with column B contains number of days (the same in your file) -
    instead of depending on row() ?

  20. #20
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Quote Originally Posted by deadlyduck View Post
    In the green part of the formula, I was doing the following:
    1. As your first dose was in row 2 and the full life was 32 days, I knew that the row in which the first dose would expire was going to be in row 33
    2. Therefore, I needed to start deducting the daily concentration of that first dose (and subsequent doses) from row 33 onwards.
    3. Each subsequent dose expired in row 35,37,39 etc
    4. So I used the MOD(row(),2) function to identify whether or not a dose expired
    5. I could then deduct the relevant quantities of doses from the total

    that's the basic idea.

    To facilitate variable strengths and concentrations, I need to use a more generalised formula- I am working on that at the moment but may be a while before I get it sorted. You might need to check back later.
    Appreciate it-thanks

  21. #21
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Quote Originally Posted by tigertiger View Post
    why don't you use the short formula:

    =E2+IF(B3<=32,(C3="x")*D3/32,-12.5*(MOD(B3,2)=1))

    with column B contains number of days (the same in your file) -
    instead of depending on row() ?
    Formula works great-thanks. Only thing is it relies on the "x"value I put in, but if the dose is taken on another day, would have to alter the x value to a different day.
    But it is working well-appreciate the help

  22. #22
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Quote Originally Posted by NBVC View Post
    Using my solution.. see attached...

    You can enter a Half-Life in H2 and a Dosage in I2 and then amend formula in E2 to:

    Please Login or Register  to view this content.
    and copy down...
    Thanks-much appreciated. Now just have to figure what the hell you did

  23. #23
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: Nested IF functions

    I've modified my original formula so that you can vary the dose and/or half-life.
    The attached has the various formulae in coloured cells or cells with a red border.
    You only need to enter the half-life data and dose- the other coloured cells should automatically compute without the 'X' marks
    Attached Files Attached Files
    Last edited by deadlyduck; 06-16-2009 at 06:42 PM.

  24. #24
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2007, 2010
    Posts
    470

    Re: Nested IF functions

    Quote Originally Posted by RyanF View Post
    Only thing is it relies on the "x"value I put in, but if the dose is taken on another day
    if you want not to rely on "x", the formula will be:
    =E2+IF(B3<=32,(MOD(B3,2)=1)*D3/32,-12.5*(MOD(B3,2)=1))

    OR
    =E2+(MOD(B3,2)=1)*IF(B3<=32,D3/32,-12.5)
    with the same number of days in the two stages (1st & 2nd stage)

    in the formulas, if also do not rely on the value in cplumn B - you can use Row() replace B3 appropriately

    G luck.
    Last edited by tigertiger; 06-17-2009 at 02:30 AM.

  25. #25
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Nested IF functions

    Thanks for the replies all. They all work, now I just have to figure out how

    Appreciate the help

+ 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