+ Reply to Thread
Results 1 to 12 of 12

Data sorting/filtering

  1. #1
    Registered User
    Join Date
    07-16-2019
    Location
    England
    MS-Off Ver
    10
    Posts
    6

    Data sorting/filtering

    I have a datasheet with columns which contain 1's and 0's. I need to identify any incidence where there are either 5 or more 1's consecutively and leave them as 1. If there are any 1's where there are less than 5 consecutively i need to change them to 0, and if there are more than 1400 1's consecutively i need to change them to 'NA'.

    I've tried:

    =IF((SUM(A1:A5)>=5),1,0) - but this excludes numbers i need to keep as 1

    I thought i could then use an aggregate formula and then change anything more than 5 to a 1

    =AGGREGATE(9,6,A1:A5) -but again this doesn't do what i need

    I thought maybe i could use an array but i'm not sure where to start. Is there a simple solution to this?

    Thanks

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Data sorting/filtering

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation with manually calculated results, explaining which information is data and which is results, and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

    To upload a file click the Go Advanced button at the foot of your post, look underneath the post area for the Manage Attachments section and take it from there.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-16-2019
    Location
    England
    MS-Off Ver
    10
    Posts
    6

    Re: Data sorting/filtering

    HI Richard

    I've attached a sample from my data as the actual file is huge.

    The data represents inactivity of a fly, so every '1' in the first column is a record of when the fly wasn't moving and every 0 means they were moving.

    When there are more than 5 '1's consecutively it means the fly was asleep, which is the information i'm interested in, but it means i need to
    to change any incidence where there are less than 5 '1's consecutively to 0.

    I can't do this manually as for each set of data i have 160 columns and 16,500 rows of data recorded.

    Would appreciate any help.

    Thanks
    Attached Files Attached Files

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

    Re: Data sorting/filtering

    Show the expected result in another column.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  5. #5
    Registered User
    Join Date
    07-16-2019
    Location
    England
    MS-Off Ver
    10
    Posts
    6

    Re: Data sorting/filtering

    I've entered another column showing what the expected result is and highlighted the cells that would change to yellow.

    Thanks
    Attached Files Attached Files

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Data sorting/filtering

    For this set of data the formula on row 6 should be

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


    I'm not sure why you are currently counting future times.

    But I'm puzzled by your reference to 160 columns. Are you saying that you have 20 sets of data each with the 8 column labels in A1:H1

  7. #7
    Registered User
    Join Date
    07-16-2019
    Location
    England
    MS-Off Ver
    10
    Posts
    6

    Re: Data sorting/filtering

    HI Richard

    Sorry what do you mean by future times, this is data that was recorded at the end of May and beginning of June.

    I haven't included all of my data here as the file is too big, so i have only included a small sample. The column labelled sleep (column D) is my raw data for 1 fly, but i have another 159 flies and their data. The other columns were how i was trying to work it out, but none of them are giving me what i actually need.

    In column D i need change any incidence of where there are less than 5 '1's consecutively to 0.

    Thanks

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

    Re: Data sorting/filtering

    In K2 then copied down.

    =AGGREGATE(14,6,--(COUNTIF(OFFSET(D2,ROW($1:$5)-ROW($5:$5),0,5),1)=5),1)
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-16-2019
    Location
    England
    MS-Off Ver
    10
    Posts
    6

    Re: Data sorting/filtering

    Hi

    That looks great, it seems to work really well, so thank you so much as i've been staring at this for days!

    Just for my own understanding would you mind explaining how the above formula works?

    Thanks

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

    Re: Data sorting/filtering

    =AGGREGATE(14,6,--(COUNTIF(OFFSET(D6,ROW($1:$5)-ROW($5:$5),0,5),1)=5),1)

    The offset formula creates five ranges.
    D2:D6, D3:D7, D4:D8, D5:D9, D6:D10

    Countif count number of 1's in each cell of five ranges.

    If count =5 result1
    if count<5, result 0

    among the five ranges highest number is selected by Aggregate function.

    I feel you can follow.

  11. #11
    Registered User
    Join Date
    07-16-2019
    Location
    England
    MS-Off Ver
    10
    Posts
    6

    Re: Data sorting/filtering

    That's perfect, thank you so much for all of your help!

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    79,380

    Re: Data sorting/filtering

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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] Filtering/Sorting Data
    By cityinbetween in forum Excel General
    Replies: 4
    Last Post: 08-06-2014, 06:34 PM
  2. sorting and filtering data
    By cpe.ppl in forum Excel General
    Replies: 2
    Last Post: 12-15-2013, 11:02 PM
  3. Data Filtering/Sorting
    By Jearnizck in forum Excel General
    Replies: 3
    Last Post: 06-11-2012, 08:31 PM
  4. Data Sorting, Matching, And/Or Filtering
    By bhenderson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2011, 06:45 AM
  5. Sorting and filtering data
    By Omega71 in forum Excel General
    Replies: 7
    Last Post: 10-29-2011, 11:54 AM
  6. Sorting/Filtering data ???
    By gws-mtc in forum Excel General
    Replies: 1
    Last Post: 04-11-2006, 04:36 PM
  7. [SOLVED] Sorting and Filtering out data
    By Chris in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-01-2005, 04:09 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