Counting Consecutive Days based on Criteria

zcavaricci

New Member
Joined
Apr 24, 2017
Messages
10
Hello,

I need to count the number occurences where blood sugar was >180 2x in a Day for =>3 consecutive days by patient. I have one table with the following structure:

Date/TimePatient IDGlucose Reading
1/28/2017 17:36A192
1/28/2017 20:12A311
1/29/2017 9:58A214
1/29/2017 10:58A181
1/30/2017 20:45A279
1/30/2017 21:45A181
1/31/2017 7:48A157
1/31/2017 12:33A157
1/31/2017 17:48A167
1/28/2017 12:35B158
1/29/2017 12:09B190
1/29/2017 17:05B211
1/30/2017 7:41B197
1/30/2017 12:05B211
1/30/2017 17:31B231
1/31/2017 21:26B188
1/5/2017 22:05C205
1/5/2017 23:40C216
1/6/2017 3:18C195
1/6/2017 7:54C187
1/7/2017 12:54C210
1/7/2017 17:22C379
1/9/2017 7:37C191

<colgroup><col><col><col></colgroup><tbody>
</tbody>


Results Expected:
Patient# Occurrences
A1
C1

<tbody>
</tbody>
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I think I understood what you're after. Copy D2 down as necessary and do likewise with C29. The D column is a helper column and can be hidden if you so desire. I suppose one could incorporate column D into the C29 formula but it would sure look ungainly.

Keep in mind that the formula finds the number of occurrences that a patient had his glucose number more than 180 at least twice a day for at least 3 consecutive days.

ABCD
1Date/TimePatient IDGlucose Reading>180 2x in a day
21/28/2017 17:36A192TRUE
31/28/2017 20:12A311TRUE
41/29/2017 9:58A214TRUE
51/29/2017 10:58A181TRUE
61/30/2017 20:45A279TRUE
71/30/2017 21:45A181TRUE
81/31/2017 7:48A157FALSE
91/31/2017 12:33A157FALSE
101/31/2017 17:48A167FALSE
111/28/2017 12:35B158FALSE
121/29/2017 12:09B190TRUE
131/29/2017 17:05B211TRUE
141/30/2017 7:41B197TRUE
151/30/2017 12:05B211TRUE
161/30/2017 17:31B231TRUE
171/31/2017 21:26B188FALSE
181/5/2017 22:05C205TRUE
191/5/2017 23:40C216TRUE
201/6/2017 3:18C195TRUE
211/6/2017 7:54C187TRUE
221/7/2017 12:54C210TRUE
231/7/2017 17:22C379TRUE
241/9/2017 7:37C191FALSE
25
26
27Results Expected:>180 2x in a Day for =>3 consecutive days
28Patient# Occurrences
29A1
30B0
31C1

<tbody>
</tbody>
Sheet14

Array Formulas
CellFormula
D2{=SUM((B2=$B$2:$B$24)*(INT(A2)=INT($A$2:$A$24))*($C$2:$C$24>180))>=2}
C29{=SUM(IF(FREQUENCY(IF(($D$2:$D$24=TRUE)*($B$2:$B$24=A29),ROW($D$2:$D$24)),IF(($D$2:$D$24<>TRUE)*($B$2:$B$24=A29),ROW($D$2:$D$24)))>=6,1,0))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try to enter the {} manually yourself.

<tbody>
</tbody>

<strike></strike>
 
Last edited:
Upvote 0
Thank DRSteele! I was hoping to have this done in MSACCESS? I know this is the MREXCEL site but there was a forum for MSACCESS so I thought I would put my question there. I will test with my data in excel until I can figure out in MSACCESS.

Michael
 
Upvote 0
Sorry, my mistake. This keeps happening when I look through the Zero-reply posts - I read it and it's Excel and then it turns into Access later. Hmmmm,.
 
Upvote 0
No Problem, I can work with what you gave me, I still get my results, just need to import the data back to MSACCESS Table ;)
 
Upvote 0
Seems to be a snafu: The formula doesn't take into account more that 6 days of >180 is still the same occurrence. I get 3 occurrences when there should be 1.

Date and TimePatient IDGlucose>180 2x in a day
1/5/2017 3:35A189FALSE
1/6/2017 20:46A182FALSE
1/7/2017 4:16A181FALSE
1/9/2017 8:16A197FALSE
1/12/2017 7:44A191TRUE
1/12/2017 16:17A181TRUE
1/14/2017 4:33A185FALSE
1/15/2017 8:05A183TRUE
1/15/2017 20:44A181TRUE
1/16/2017 4:14A189TRUE
1/16/2017 15:27A182TRUE
1/17/2017 11:39A181FALSE
1/18/2017 16:00A185FALSE
1/19/2017 11:24A183FALSE
1/24/2017 6:23A205TRUE
1/24/2017 15:24A199TRUE
1/24/2017 21:02A197TRUE
1/25/2017 5:42A218TRUE
1/25/2017 18:03A265TRUE
1/25/2017 21:39A208TRUE
1/26/2017 6:02A246TRUE
1/26/2017 10:11A215TRUE
1/26/2017 14:33A238TRUE
1/26/2017 21:20A192TRUE
1/27/2017 5:54A236TRUE
1/27/2017 9:51A215TRUE
1/27/2017 13:21A264TRUE
1/27/2017 21:46A255TRUE
1/28/2017 5:28A252TRUE
1/28/2017 10:09A226TRUE
1/28/2017 13:33A240TRUE
1/28/2017 21:57A230TRUE
1/29/2017 4:59A203TRUE
1/29/2017 13:00A224TRUE
1/29/2017 22:11A201TRUE
1/30/2017 6:21A201FALSE
PatientOccurrence
A3

<tbody>
</tbody><colgroup><col><col><col><col></colgroup>
 
Upvote 0
I get 1. There is 1 occurrence.

I pasted your new data to my spreadsheet. My data goes like below. [For mercy's sake, I eliminated many rows here; I'm sure you follow.]

ABCD
35Date and TimePatient IDGlucose>180 2x in a day
361/5/2017 3:35A189FALSE
73Results Expected:>180 2x in a Day for =>3 consecutive days
74Patient# Occurrences
75A1

<tbody>
</tbody>
Sheet14

Array Formulas
CellFormula
D36{=SUM((B36=$B$36:$B$71)*(INT(A36)=INT($A$36:$A$71))*($C$36:$C$71>180))>=2}
C75{=SUM(IF(FREQUENCY(IF(($D$36:$D$71=TRUE)*($B$36:$B$71=A75),ROW($D$36:$D$71)),IF(($D$36:$D$71<>TRUE)*($B$36:$B$71=A75),ROW($D$36:$D$71)))>=6,1,0))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try to enter the {} manually yourself.

<tbody>
</tbody>
 
Last edited:
Upvote 0
Sorry, my mistake. This keeps happening when I look through the Zero-reply posts - I read it and it's Excel and then it turns into Access later. Hmmmm,.
In the "Zero Reply Posts", if you look all the over to the right, it tells you which forum each thread is in.
Many people fail to notice that!;)
 
Upvote 0
Question: if there are four consecutive days (say days Jan 1, Jan 2, Jan 3, and Jan 4) ...

do you count this as "2" since it's two sets of consecutive days {1,2,3} and {2,3,4}?
or do you count it as "1" since it's one set of consecutive days >= 3
 
Upvote 0

Forum statistics

Threads
1,221,699
Messages
6,161,367
Members
451,700
Latest member
Eccymarge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top