+ Reply to Thread
Results 1 to 15 of 15

Trying to reference an array within a formula to output corresponding value

  1. #1
    Registered User
    Join Date
    10-03-2022
    Location
    Oakville, Ontario
    MS-Off Ver
    365
    Posts
    38

    Post Trying to reference an array within a formula to output corresponding value

    Hi,

    Test Formula.xlsx

    I am trying to make a Nutritional Value Chart that accurately displays all macro and micro nutrient data - appropriate to the demographic you input at the top.

    I want the formulas within the min, recommended, and max columns to auto update with the correct information; according to the demographic information input above. That is to say, a child needs a different amount of protein and sodium, or a pregnant woman needs a different amounts of calories etc.

    I can find all this information, and have the macros, vitamins, and mineral values on a separate sheet within the document. The only thing I don't know how to do is create a formula that references the array and correctly selects the appropriate value based on ***, and age.

    A secondary question is, how can I make the charts on Nutrition Data sheet into tables with headings that span multiple columns?

    The questions are posed within the document encase this wasn't clear.

    Thank you!
    Last edited by CVDom; 02-16-2024 at 09:36 AM.

  2. #2
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Trying to reference an array within a formula to output corresponding value

    Here is an example of how it might work.
    1. Add columns (AT:AV) to the Nutrient Data sheet for minimum age, maximum age and gender/pregnant/lactating
    2. Add a dropdown for pregnant/lactating in cell F2 on the Reccomended Nutrition Values sheet.
    3. Populate the Vitamin A section of the Reccomended Nutrition Values sheet using:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  3. #3
    Registered User
    Join Date
    10-03-2022
    Location
    Oakville, Ontario
    MS-Off Ver
    365
    Posts
    38

    Re: Trying to reference an array within a formula to output corresponding value

    Amazing! This does exactly what I was hoping for! Thank you.

    If it isn't too much trouble could you explain how it works? I've tried to understand indexes before - to no avail, and this is my first time with aggregate function, or row function.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Trying to reference an array within a formula to output corresponding value

    FYI, as you have 365, you can use:

    =FILTER('Nutrient Data'!$B$19:$D$45,('Nutrient Data'!$AT$19:$AT$45<=Demographic[Age])*('Nutrient Data'!$AU$19:$AU$45>=Demographic[Age])*(('Nutrient Data'!$AV$19:$AV$45=Demographic[***])+('Nutrient Data'!$AV$19:$AV$45=$F$2)))

    instead. Just enter that into B40 and clear B41 and C40:D41
    Rory

  5. #5
    Registered User
    Join Date
    10-03-2022
    Location
    Oakville, Ontario
    MS-Off Ver
    365
    Posts
    38

    Re: Trying to reference an array within a formula to output corresponding value

    Heyyy, I like the spill feature, very nice! But how do I change the formula so that it doesn't spill into a row below when Pregnant or Lactating are selected, I want those values to override the original female values. - And of course for the proper age.

    Thank you!

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Trying to reference an array within a formula to output corresponding value

    Can you clarify exactly what you want to happen for each possible value?

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Trying to reference an array within a formula to output corresponding value

    Re post #3.
    I will be glad to explain as best I can; however, I would ask that you first select cell C41 and utilize the Evaluate Formula feature to see the formula in action.

  8. #8
    Registered User
    Join Date
    10-03-2022
    Location
    Oakville, Ontario
    MS-Off Ver
    365
    Posts
    38

    Re: Trying to reference an array within a formula to output corresponding value

    @Rorya I'm trying to have it filter the corresponding values from the Nutrition Data sheet to the Nutrition Values form on the "Reccomended Nutrition Values" sheet. For example Vitamin A Female 18 years old Lactating would then display only these three values: 885, 1200, 2800 (Min, Recommended, Max) in cells: B40, C40, D40. The same effect would be true for each other micro nutrient: displaying their corresponding values.

    What you provided works very well, but has two sets of values when one selects Pregnant/Lactating. One set of values is the values for *** and age, the other displayed below is the corresponding value for ***, age and pregnant/lactating status. - This extra row of information is not displayed when "Neither" is selected. What should happen is that if Lactating is selected for example then the only set of values displayed should reflect the values of the age of the lactating person.

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Trying to reference an array within a formula to output corresponding value

    Oh OK - then try:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    I assume you can work out what to change the *** to?

  10. #10
    Registered User
    Join Date
    10-03-2022
    Location
    Oakville, Ontario
    MS-Off Ver
    365
    Posts
    38

    Re: Trying to reference an array within a formula to output corresponding value

    Thanks JeteMc! Looks like it selects a range then compares it to the selection on the Reccommended Nutrition Values sheet, True, False etc. That's as much as I understand for now. I'll have to research the Index, aggregate, and row functions on my own. Thank you!

  11. #11
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Trying to reference an array within a formula to output corresponding value

    You are correct, the INDEX function tells the formula what the range is.
    The AGGREGATE function in this case could be thought of as being LARGE since the first argument is 14.
    The second argument is 6 which ignores the #DIV/0! errors that will occur when a value in the array is divided by the Boolean value false.
    The reason I used AGGREGATE is because the function will automatically handle arrays.
    The ROW function is used to produce an array whereas the ROWS function returns a single value.
    I hope that makes sense and is helpful.
    Let us know if you have any questions.

  12. #12
    Registered User
    Join Date
    10-03-2022
    Location
    Oakville, Ontario
    MS-Off Ver
    365
    Posts
    38

    Re: Trying to reference an array within a formula to output corresponding value

    @rorya this works great! I just noticed though it doesn't work for people younger than 9, even though that data is available on the Nutrition Data sheet, and at that age the values ignore ***/gender and also include months. Can that be incorporated somehow? I don't mind changing the way the values are displayed (0-6 mo could be 0-0.5 years).

    @JeteMC Thank you for the explanation, I'm not sure I follow the index portion or the "arguments" section of the aggregate function but I definitely have a better grasp of the concept. I'll look into these gaps in knowledge later. Thank you very much!

  13. #13
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Trying to reference an array within a formula to output corresponding value

    Here is a link to the INDEX function: https://support.microsoft.com/en-us/...2-b56b061328bd
    The syntax is INDEX(array, row_num, [column_num])
    array is the range to cells that will be evaluated using the row_num and column_num arguments.
    In the case of my formula the AGGREGATE function supplies the row_num and the COLUMNS function supplies the column_num.
    Here is a link to the AGGREGATE function: https://support.microsoft.com/en-us/...6-e19993fa26df
    The syntax is AGGREGATE(function_num, options, array, [k])
    function_num is the first argument and options is the second.

  14. #14
    Registered User
    Join Date
    10-03-2022
    Location
    Oakville, Ontario
    MS-Off Ver
    365
    Posts
    38

    Re: Trying to reference an array within a formula to output corresponding value

    For those who come to this thread in the future. Here is the final result
    Please Login or Register  to view this content.
    The INDEX allows the SEQUENCE function to control how many levels of spill result (in this case 3). The FILTER; filters... Then the array is set: "B2_Riboflavin" (I made each element, vitamin, and trace mineral into it's own table. I also made the age range, and *** ($EX) into it's own table at the beginning of each Nutrition Data sheet chart. Couple more changes: the infant and children ranges were duplicated and added to the beginning of each gender so as to keep things simple.

    Please Login or Register  to view this content.
    The formula for zinc is slightly different, multiplying the result by 1.5 if the demographic is a vegetarian (because the bio-availability of zinc is lower in plants, than in animals).

    Or you can add stuff as is the case with Vitamin C:
    Please Login or Register  to view this content.
    Because smoking increases oxidative stress and metabolic turnover of vitamin C, the requirement for smokers is increased by 35 mg/day.

    Thanks all for your help! SOLVED

  15. #15
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,569

    Re: Trying to reference an array within a formula to output corresponding value

    Thank You for the feedback and for marking the thread as 'Solved'. I hope that you have a blessed day.

+ 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] Counting entries from an array formula output
    By nickfelton in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-21-2023, 01:03 AM
  2. [SOLVED] Array to embed formula and if number of output is met output Blank
    By ywang in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-29-2015, 02:34 AM
  3. [SOLVED] Cell reference, output dates to numeric. Should output as text
    By lifeseeker1019 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-02-2015, 05:51 PM
  4. Cell reference must work with formula output, not formula itself
    By Irdanwen in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-20-2012, 11:19 AM
  5. convert array formula output to string
    By MCCCLXXXV in forum Excel General
    Replies: 2
    Last Post: 07-07-2011, 11:57 AM
  6. Function/ formula to output a cell reference
    By Creator in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 02-17-2006, 05:30 PM
  7. customise array formula output
    By TUNGANA KURMA RAJU in forum Excel General
    Replies: 0
    Last Post: 10-25-2005, 01:05 AM

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