Grouping Consecutive Values by Min and Max

MCTampa

Board Regular
Joined
Apr 14, 2016
Messages
97
I have the following table for which I would like to create groups of consecutive weeks by min and max values.

AREA CodeWeek
3301
3302
3303
3304
33033
33034
33035
33036
33037
33038
33039
33040
33041
33042
33043
33044
33045
33047
33048
33049
33050

<caption> Automatics </caption><thead>
</thead><tbody>
</tbody><tfoot></tfoot>

The end result I would like is:

Area CodeWeek StartWeek End
33014
3303345
3304750

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

I'm trying to write this in SQL but many of the solutions I've found online reference using the ROW_NUMBER() function which Access does not recognize.

Can someone please help me out?
Thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Note: This is relative to the area. So the groupings for area 330 will be independent of another area, but the logic will remain the same.
 
Upvote 0
Got the answer at Stack Overflow.
Thanks anyway!

<code>select area, min(week), max(week)
from (select t.*,
(select count(*)
from t as t2
where t2.area = t.area and t2.week <= t.week
) as seqnum
from t
) as t
group by area, (week - seqnum);</code>
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,487
Members
448,967
Latest member
visheshkotha

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