+ Reply to Thread
Results 1 to 12 of 12

Help with complex formula, with XLOOKUP

Hybrid View

sanspm Help with complex formula,... 11-18-2021, 07:41 PM
WideBoyDixon Re: Help with complex formula 11-18-2021, 07:46 PM
sanspm Re: Help with complex formula 11-18-2021, 07:48 PM
WideBoyDixon Re: Help with complex formula 11-18-2021, 07:51 PM
sanspm Re: Help with complex formula 11-18-2021, 08:31 PM
FlameRetired Re: Help with complex formula 11-18-2021, 07:56 PM
sanspm Re: Help with complex... 11-18-2021, 08:24 PM
WideBoyDixon Re: Help with complex... 11-18-2021, 08:59 PM
sanspm Re: Help with complex... 11-18-2021, 09:45 PM
WideBoyDixon Re: Help with complex... 11-19-2021, 03:16 AM
WideBoyDixon Re: Help with complex... 11-19-2021, 04:23 AM
sanspm Re: Help with complex... 11-23-2021, 01:46 AM
  1. #1
    Registered User
    Join Date
    12-01-2020
    Location
    Vancouver
    MS-Off Ver
    365
    Posts
    19

    Help with complex formula, with XLOOKUP

    I'm hoping that somebody smarter than me can help me out with a complicated formula I'm having trouble designing. Attached is the file.

    Cell R16 should calculate the total kg of a medicine called "F100" based on the number of days in treatment (user entered data in R13), the average daily weight gain (user entered data in R14), and weight of the patient at admission (user entered data in R4). The weight-based dosage chart of F100 is in columns B-G.


    The formula should look something like this:
    On day 1 of treatment, the patient should get the amount listed in the dosage chart (Column G based on their weight that day) +
    On day 2 of treatment, the patient should get the amount listed in the dosage chart (Column G based on their weight that day, which is weight at admission plus the weight gained since admission) +
    .....
    On day N of treatment (cell R13), the patient should get the amount listed in the dosage chart (Column G based on their weight that day, which is weight at admission plus the weight gained since admission)
    = The total amount provided to the patient based on their weight at admission and average daily weight gain

    Many thanks for any suggestions!
    Attached Files Attached Files
    Last edited by sanspm; 11-23-2021 at 01:47 AM. Reason: solved

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Help with complex formula

    The daily weight gain is given as 10 so after 1 day the weight will be 15.1kg and after 45 days it will be 455.1kg - that's quite a lot! Perhaps daily weight gain is measure in something else?

    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Registered User
    Join Date
    12-01-2020
    Location
    Vancouver
    MS-Off Ver
    365
    Posts
    19

    Re: Help with complex formula

    Quote Originally Posted by WideBoyDixon View Post
    The daily weight gain is given as 10 so after 1 day the weight will be 15.1kg and after 45 days it will be 455.1kg - that's quite a lot! Perhaps daily weight gain is measure in something else?

    WBD
    Ha! Good catch! That weight gain is usually reported as grams per kg of body weight per day. When I tried to develop the formula myself I made sure to divide that by 1000.

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Help with complex formula

    Give this a try then:

    =SUMPRODUCT(XLOOKUP(R4+R14*(ROW($A$1:INDEX($A:$A,R13))-1)/1000,B6:B26,G6:G26,,-1))
    WBD

  5. #5
    Registered User
    Join Date
    12-01-2020
    Location
    Vancouver
    MS-Off Ver
    365
    Posts
    19

    Re: Help with complex formula

    Thanks WBD!

    This almost works, but it looks like I made a mistake in the way I explained how the weight is calculated. The incremental daily weight gain is on "yesterday's" weight and not on the starting weight.

    I plugged in your formula into R16 and I did a manual calculation to cross-check the results to see if it works as expected. Ultimately the formula should return a value of 2.64 rather than 2.11. Is that a relatively easy modification or does it overly complicate things?

    Reattaching the worksheet with your formula and my semi-manual calculation.
    Attached Files Attached Files

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,742

    Re: Help with complex formula

    Administrative Note:

    Welcome to the forum.

    sanspm We would very much like to help you with your query, however the thread title does not really convey what your request is about. Tell us what you are trying to do, not how you think it should be done.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Dave

  7. #7
    Registered User
    Join Date
    12-01-2020
    Location
    Vancouver
    MS-Off Ver
    365
    Posts
    19

    Re: Help with complex formula, including XLOOKUP

    I was instructed to change the title of my thread. I don't really know the right terms to use, but hopefully this is enough to re-open my request for help.

  8. #8
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Help with complex formula, with XLOOKUP

    It seems like you made a change to the Daily weight gain - you initially said this was measured in grams but your new calculation has this as a percentage weight gain! In which case I think this is correct according to your manual calculation:

    =SUMPRODUCT(MAXIFS($G$6:$G$96,$B$6:$B$96,"<="&R4*(1+$R$14/100)^(ROW($A$1:INDEX($A:$A,R13+1))-1)))
    WBD

  9. #9
    Registered User
    Join Date
    12-01-2020
    Location
    Vancouver
    MS-Off Ver
    365
    Posts
    19

    Re: Help with complex formula, with XLOOKUP

    Thanks for your ongoing help WBD and sorry for any confusion caused by my miscommunication / formula errors! I hope this is the last time I ask for your help...

    It *is* actually grams and not percentage, based on the previous day's weight, and is x grams gain per kg of body weight per day.

    In this particular example it's a gain of 5 grams per kg of body weight per day. So, a child starting treatment at 6kg:
    would presumably gain 30.0 grams by the second day of treatment to be 6.03 kg
    and then would gain another 30.1 grams by the third day of treatment to be 6.06 kg
    and then would gain another 30.3 grams by the fourth day of treatment to be 6.09 kg
    .....

    Thanks for your patience!

  10. #10
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Help with complex formula, with XLOOKUP

    Ah. OK. Then just change the 100 to 1000 above:

    =SUMPRODUCT(MAXIFS($G$6:$G$96,$B$6:$B$96,"<="&R4*(1+$R$14/1000)^(ROW($A$1:INDEX($A:$A,R13+1))-1)))
    WBD

  11. #11
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Help with complex formula, with XLOOKUP

    So then I started poking around at the calculation in column G which, after simplification, is [Column B]*37/50 so I came up with another couple of formulas. The first one performs the same calculation as above without using the lookup table:

    =SUMPRODUCT(FLOOR.MATH(R4*(1+$R$14/1000)^(ROW($A$1:INDEX($A:$A,R13+1))-1),0.2)*37/1050)
    The second one is based on the calculation against the exact weight (without using the 0.2 increments) and disposes of the FLOOR.MATH part:

    =SUMPRODUCT(R4*(1+$R$14/1000)^(ROW($A$1:INDEX($A:$A,R13+1))-1)*37/1050)
    Just my natural mathematical curiosity coming to the fore ...

    WBD

  12. #12
    Registered User
    Join Date
    12-01-2020
    Location
    Vancouver
    MS-Off Ver
    365
    Posts
    19

    Re: Help with complex formula, with XLOOKUP

    Many, many thanks WBD! I never would have figured this out without your help.

    The version that I think makes the most sense is the one that uses the lookup table because the "dosage" table that is actually used might be slightly different from what I have in the sample data. I'll plug this one into the workbook.

    Thanks again!

+ 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. [SOLVED] Complex formula getting moer complex
    By Trebor777 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-02-2017, 01:39 PM
  2. Complex IF formula.
    By Smasen91 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-25-2016, 12:53 PM
  3. [SOLVED] Use an existing cell formula for creating a new more complex formula
    By dubcap01 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-23-2014, 07:41 AM
  4. complex AVG formula
    By koosh1986 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-22-2014, 06:46 PM
  5. Replies: 4
    Last Post: 02-03-2014, 12:47 AM
  6. Need help with complex formula!
    By bcoluc1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-20-2013, 02:07 AM
  7. complex formula?
    By spinkung in forum Excel General
    Replies: 1
    Last Post: 12-22-2009, 05:20 AM

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