+ Reply to Thread
Results 1 to 11 of 11

Help fix formula to Get random sample from DATA in a column D from a list

Hybrid View

  1. #1
    Registered User
    Join Date
    05-09-2022
    Location
    Chile
    MS-Off Ver
    365
    Posts
    8

    Post Help fix formula to Get random sample from DATA in a column D from a list

    Hello, in the link below is a sheet with the data i have. Each day of the year in column A and is repeated 24 times except for day 1 which has 16 entries. This data represents the DATA obtained at each our of the day for a whole year, SO each day have 24 data entries in column D which is basically 1 data entry every hour of the day. What i must do is get a random sample from D out of all the day entries and put the result in Column F as indicated. Get 1 random data out of the 24 data entries of each day. So to speak, Day 1, get data from at 13:00, from day 2, data from 19:00 and so on, though the hours are not marked but you have 24 entries per day unless the data is missing. So how can i fix the formula or create a new one?

    One thing i dont understand is why the formula works in google sheets but not in excel. The formula works for the first 31 days only for some reason and i get the message in EXCEL in the PC "The first argument of LET must be a valid name" if i try to use the formula in it and dosnt works.... So im left confused, any ideas? Formula that i tried only works in sheets for the first 31 days but dosnt works in excel. =LET(_a,FILTER(ROW(D:D),A:A=ROW()-1),IFERROR(INDEX(D:D,RANDBETWEEN(MIN(_a),MAX(_a))),""))

    Here i made an easy-to-understand sample of what i need.

    Excel Help.xlsx
    Last edited by Treyon; 06-22-2023 at 08:00 PM.

  2. #2
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    UDF solution acceptable?
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  3. #3
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    Please remove the _ in your formula (3 times).
    So replace "_a" by "a" (3 times).
    Last edited by HansDouwe; 06-21-2023 at 12:47 AM.

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    In G2.
    Formula: copy to clipboard
    =LET(a,SEQUENCE(INT(COUNTA(A:A)/24)+1),b,IFERROR(INDEX(D:D,IF(a=1,RANDBETWEEN(1,17),RANDBETWEEN(18+(a-2)*24,41+(a-2)*24))),""),HSTACK(a,b))
    Attached Files Attached Files
    Last edited by kvsrinivasamurthy; 06-21-2023 at 03:16 AM.

  5. #5
    Registered User
    Join Date
    05-09-2022
    Location
    Chile
    MS-Off Ver
    365
    Posts
    8

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    Quote Originally Posted by kvsrinivasamurthy View Post
    In G2.
    Formula: copy to clipboard
    =LET(a,SEQUENCE(INT(COUNTA(A:A)/24)+1),b,IFERROR(INDEX(D:D,IF(a=1,RANDBETWEEN(1,17),RANDBETWEEN(18+(a-2)*24,41+(a-2)*24))),""),HSTACK(a,b))
    Hi, thanks for the formula, i checked it and it works partially, Sometimes it takes 2 random numbers from the same day, I modified the data to clearly see the issue and the numbers in Column I marked in red/yellow are mistaken. I added a conditional formatting to see it.
    So there is an issue with the formula but i cant fix it. Also for some reason, the sometimes when the formula is used, the first DATA takes the title of the column.
    In columns J and K, I added the lowest and highest value that the random data should give and Column I gives the difference between them, if the result is above 0 or lower than -24, the data is not correct and something is wrong with the formula.
    THanks for the help, waiting for the reply.

    Excel Help ans MODIFIED.xlsx

  6. #6
    Registered User
    Join Date
    05-09-2022
    Location
    Chile
    MS-Off Ver
    365
    Posts
    8

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    Quote Originally Posted by kvsrinivasamurthy View Post
    In G2.
    Formula: copy to clipboard
    =LET(a,SEQUENCE(INT(COUNTA(A:A)/24)+1),b,IFERROR(INDEX(D:D,IF(a=1,RANDBETWEEN(1,17),RANDBETWEEN(18+(a-2)*24,41+(a-2)*24))),""),HSTACK(a,b))
    HI, I tried using this formula, it works perfectly BUT.... i cannot find how can i expand it to the end and make it work properly... if i expand it, the cells selection in the formula only advances 1 number From D2:D25 to D3:D26 for example...

    =INDEX(D2:D25;RANDBETWEEN(1;ROWS(D2:D25))) I have this formula for the random data for the first 24 items. What this does is select randomly a data from the selection of 24 cells.

    =INDEX(D26:D49;RANDBETWEEN(1;ROWS(D26:D49))) And this one for the next 24 cells and so on....

    THe next one would be...

    =INDEX(D50:D73;RANDBETWEEN(1;ROWS(D50:D73)))... I must advance the formula 24 cells every time. Until i hit 10000....

    How do i fix the formula so that i can do this over 400 times and make it automatic? I tried to see if i can apply math to the sell selection but i cannot think how. I cannot write the formula manually in each cell... Best would be for the formula to advance 24 cells on its own rather than 1 cell at a time when i expand it

  7. #7
    Registered User
    Join Date
    03-09-2023
    Location
    Nevada, USA
    MS-Off Ver
    2021
    Posts
    10

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    In cell F1, you can use the following formula:
    =IF(A1=1, INDEX(D1:D16, RANDBETWEEN(1, 16)), INDEX(OFFSET(D2, (A1-2)*24, 0, 24, 1), RANDBETWEEN(1, 24)))

    This formula checks if it's Day 1, and if so, it selects a random entry from D1 to D16. For the other days, it uses the OFFSET function to shift the range by the appropriate number of rows and selects a random entry from the 24 available.

  8. #8
    Registered User
    Join Date
    05-09-2022
    Location
    Chile
    MS-Off Ver
    365
    Posts
    8

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    Quote Originally Posted by beecerealcello View Post
    In cell F1, you can use the following formula:
    =IF(A1=1, INDEX(D1:D16, RANDBETWEEN(1, 16)), INDEX(OFFSET(D2, (A1-2)*24, 0, 24, 1), RANDBETWEEN(1, 24)))

    This formula checks if it's Day 1, and if so, it selects a random entry from D1 to D16. For the other days, it uses the OFFSET function to shift the range by the appropriate number of rows and selects a random entry from the 24 available.
    i see... using an if... What i did while i was waiting was use =INDEX(B 2 :B 17 ;RANDBETWEEN(1;ROWS(B 2 :B 17 ))) in excel, and i pasted each word in a separate cell as. then i copied it down until the end. After that i just had to make the numbers that represent the cells be correct. I used Previous Number+24 and finally i copied it down to notedpad, remove any unwanted spaces and paste it down in excel. It worked perfectly... Problem is that after doing this... i found out that some days have 23 entries, some have 25 entries, which i find it extremely odd. If it has less... well, one hour was not registered.. but to have 25? means that somehow it did not follow the rules to register data every 60 min.... THen i thought, how do i fix it... i can use =A2-DATE(YEAR(A2);1;0) instead of =day to get the day of the year and use that as a condition somehow.... How would you modify the formula? I must point out that the data is not numbers from 1 to 90000 or somethign. each day has numbers like 83853,139493277499 and the like.... Is there a function that allows me to count how many entries are per day? This may help out cause the data entries are inconsistent. Some days have 23, others 24 and others 25.... So if i can count how many of those are and apply that number to the rows that need to be selected it may do the job

  9. #9
    Registered User
    Join Date
    05-09-2022
    Location
    Chile
    MS-Off Ver
    365
    Posts
    8

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    Thanks, i have solved the issue. Since i couldnt use a single formula, i used 4. What i did was obtain the number of the year that each date represented. Counted each of those and obtained the number. Then i wrote the formula by parts in excel leaving the cell number alone, and then i pasted there the result of each count of the days. Then i copied the whole formula in notepad, removed the extra spaces and i pasted it in excel. It game me something like this.
    =INDEX(B 2 :B 17 ;RANDBETWEEN(1;ROWS(B 2 :B 17 )))
    =INDEX(B 18 :B 41 ;RANDBETWEEN(1;ROWS(B 18 :B 41 )))
    =INDEX(B 42 :B 65 ;RANDBETWEEN(1;ROWS(B 42 :B 65 )))
    =INDEX(B 66 :B 89 ;RANDBETWEEN(1;ROWS(B 66 :B 89 )))
    =INDEX(B 90 :B 113 ;RANDBETWEEN(1;ROWS(B 90 :B 113 )))
    =INDEX(B 114 :B 137 ;RANDBETWEEN(1;ROWS(B 114 :B 137 )))
    =INDEX(B 138 :B 161 ;RANDBETWEEN(1;ROWS(B 138 :B 161 )))
    =INDEX(B 162 :B 185 ;RANDBETWEEN(1;ROWS(B 162 :B 185 )))
    =INDEX(B 186 :B 209 ;RANDBETWEEN(1;ROWS(B 186 :B 209 )))
    =INDEX(B 210 :B 233 ;RANDBETWEEN(1;ROWS(B 210 :B 233 )))
    =INDEX(B 234 :B 257 ;RANDBETWEEN(1;ROWS(B 234 :B 257 )))
    =INDEX(B 258 :B 281 ;RANDBETWEEN(1;ROWS(B 258 :B 281 )))
    =INDEX(B 282 :B 305 ;RANDBETWEEN(1;ROWS(B 282 :B 305 )))
    I posted this and i solved the problem. No longer the data is inconrrect and it used the appropiate number of entries per day even if they are different.

  10. #10
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    Ref Post#6
    Pl attach a file showing the problem.

  11. #11
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Help fix formula to Get random sample from DATA in a column D from a list

    Since your version is 365 formula is to be entered only in G2. Formula should not be copied to other cells. Formula will spill out and entire result is obtained depending on number rows of input data.

+ 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. Need help deleting random sample from list.
    By Hites_05 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2022, 04:57 PM
  2. Which data set has the best overlap with a random sample
    By snomis in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-20-2017, 10:05 AM
  3. Transfer random selected sample values to another column
    By Smash1987 in forum Excel General
    Replies: 1
    Last Post: 11-06-2014, 11:33 PM
  4. How to get a random sample from list
    By mrotsliah in forum Excel General
    Replies: 2
    Last Post: 10-10-2014, 03:03 PM
  5. How do I create a random sample from a list?
    By swrath in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-23-2005, 11:35 AM
  6. [SOLVED] How do I pull a random sample of people from a list in excel?
    By PM in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-29-2005, 12:45 AM
  7. Random sample selection list
    By scroller in forum Excel General
    Replies: 0
    Last Post: 04-27-2005, 04:15 PM

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