Apple Intelligence is now available on iPhone, iPad, and Mac!

Help with Formula on Numbers

I have a spreadsheet for my wife, it is a daily activity calendar with a separate "activity" list depending on the weather and availability. I wanted a way for her to be able to click of select a category and a randomly selected activity would appear.


For example, Monday at 9:00 is sunny so she can click a sell and a random activity from the "sunnyday" sheet is selected.


I am planning on expanding the list and category so would be needed later on.

Posted on Oct 10, 2024 2:35 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 11, 2024 1:49 PM

> Would it be possible for only one activity to change, while the others remain fixed?


Not using RANDBETWEEN()


That function will re-run any time the spreadsheet is updated. That's an inherent limitation of the RAND/RANDBETWEEN function.


The alternative would be to craft something pseudo-random that keys off the date - for example, instead of the RANDBETWEEN() to choose a number, you could set cell B5 to something like:


=INDIRECT(B$2&"::A"&1+MOD(DAY(TODAY())+COLUMN(),COUNTA(INDIRECT(B$2&"::Activities"))))


This takes TODAY()'s date, and extracts the day number from it (e.g. October 11th 2024 -> 24), which is then added to the column number (to get variance based on the day, otherwise all 'Sunny' days get the same activity) and passed through MOD() with the number of Activities, and this is used as the index to the table.

This reduces the randomness to once per day - every time you look at the sheet on the same day it will have the same values, but open it tomorrow and it will change because TODAY() now has a different value.


If you have a cell on the sheet with a date value you can substitute that for TODAY(), then the activities would be consistent for that date regardless of when you view it.


5 replies
Question marked as Top-ranking reply

Oct 11, 2024 1:49 PM in response to Dubbia

> Would it be possible for only one activity to change, while the others remain fixed?


Not using RANDBETWEEN()


That function will re-run any time the spreadsheet is updated. That's an inherent limitation of the RAND/RANDBETWEEN function.


The alternative would be to craft something pseudo-random that keys off the date - for example, instead of the RANDBETWEEN() to choose a number, you could set cell B5 to something like:


=INDIRECT(B$2&"::A"&1+MOD(DAY(TODAY())+COLUMN(),COUNTA(INDIRECT(B$2&"::Activities"))))


This takes TODAY()'s date, and extracts the day number from it (e.g. October 11th 2024 -> 24), which is then added to the column number (to get variance based on the day, otherwise all 'Sunny' days get the same activity) and passed through MOD() with the number of Activities, and this is used as the index to the table.

This reduces the randomness to once per day - every time you look at the sheet on the same day it will have the same values, but open it tomorrow and it will change because TODAY() now has a different value.


If you have a cell on the sheet with a date value you can substitute that for TODAY(), then the activities would be consistent for that date regardless of when you view it.


Oct 11, 2024 11:26 AM in response to Alexrola

I reformatted the tables a little bit, and read between the lines on how this should work, but hopefully this will give you a starting point.


First, I created separate tables for the Sunny day and Rainy days (I'm guessing these are already separate tables, but it isn't clear from the screenshot). These tables were named appropriately (important) and had the same 'Activities' heading (also important). For example:


(you can put whatever text you like in them, and they don't have to have the same number of items).

I wasn't sure how 'Quiet time' and Music & Movement fit into this, since they could apply on any day... but hopefully that's something you can implement.


Second change was a second Header row on the main calendar table - this is where you enter the weather for the day. The cells in this row are formatted as 'Pop-up menu', with options that match the table names created above (e.g. 'Sunny', 'Rainy', etc.) - that's why the table names are important).



Now comes the magic. The cells in the calendar create a dynamic lookup using the value of the pop-up menu to determine which table to fetch data from.


The formula in cell B5, for example, is:


=INDIRECT(B$2 & "::A" & RANDBETWEEN(2, 1+COUNTA(INDIRECT(B$2 & "::Activities"))))


This does several things. First, the INDIRECT() function is used to build a reference to another cell. In this case, we use the value of B$2 (the 'weather' popup in the current day) to identify the table name to use (which is why the activity table names are important). We add to that '::A' (to reference column A in that table), plus a random number between 2 (avoiding the header row) and the number of values in the 'Activities' column (hence the importance of the column header).


Now each time you select a value from the pop-up menu (e.g. either Sunny or Rainy) the cell updates with a new random item from the appropriate table.


Like I said, I don't know how this relates to the Quiet and Music activities, but hopefully you can expand this idea to incorporate them as needed.



Help with Formula on Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.