Formula to count consecutive values in a range

Folander

New Member
Joined
Feb 16, 2016
Messages
18


Hi Everyone,

I have you can help me, I need a formula to count the latestconsequetive times a location is in a range.

Example below:


Jan
Feb
Mar
Apr
May
June
July
Aug
Sep
Oct
London
London
London
Paris
Paris
London
London
London
London
London
<tbody> </tbody>


In an ideal world in a cell I would like to return for thecity line, a count of 5 for 5 month of London as the first 3 months should be disregardedas they have been broken by other cities.


Thanks for reading!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
JanFebMarAprMayJuneJulyAugSepOctNovDecJanFebMarAprMayJune
LondonLondonLondonParisParisLondonLondonLondonLondonLondonGenevaTokyoTokyoTokyoLondonLondonLondonLondon
123121234511231234
000020000010030004
using 2 helper rows the latest run for each city is marked
formula in A4
=IF(ISERROR(MATCH(A2,B$2:$Z$2,0)),A3,0)

<colgroup><col width="64" span="19" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
Thanks Old Brewer, the issue is and I guess I should have mentioned it; I will have a list of 100+ staff with their locations over the course of the year, so I don’t think I can use your suggestion. If you can think of any other ideas that would be great.
 
Last edited:
Upvote 0
JanFebMarAprMayJuneJulyAugSepOctNovDecJanFebMarAprMayJune
fredLondonLondonLondonParisParisLondonLondonLondonLondonLondonGenevaTokyoTokyoTokyoLondonLondonLondonLondon
billParisParisLondonLondonLondonLondonLondonGenevaTokyoTokyoBathBathBathBathYorkYorkYorkYork
sidBathBathBathBathParisParisLondonLondonLondonLondonLondonGenevaTokyoTokyoYorkYorkYorkYork
daveYorkYorkYorkYorkBathBathBathBathParisParisLondonLondonLondonLondonLondonGenevaTokyoTokyo
harryParisParisLondonLondonLondonLondonLondonGenevaTokyoTokyoYorkYorkYorkYorkBathBathBathBath
using this example - what do you want ?

<colgroup><col width="64" span="19" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
Jan
Feb
Mar
Apr
May
June
July
Aug
Sep
Oct
Nov
Dec
Jan
Feb
Mar
Apr
May
June
fred
London
London
London
Paris
Paris
London
London
London
London
London
Geneva
Tokyo
Tokyo
Tokyo
London
London
London
London
bill
Paris
Paris
London
London
London
London
London
Geneva
Tokyo
Tokyo
Bath
Bath
Bath
Bath
York
York
York
York
sid
Bath
Bath
Bath
Bath
Paris
Paris
London
London
London
London
London
Geneva
Tokyo
Tokyo
York
York
York
York
dave
York
York
York
York
Bath
Bath
Bath
Bath
Paris
Paris
London
London
London
London
London
Geneva
Tokyo
Tokyo
harry
Paris
Paris
London
London
London
London
London
Geneva
Tokyo
Tokyo
York
York
York
York
Bath
Bath
Bath
Bath
using this example - what do you want ?

<tbody>
</tbody>

To the right of the latest month, I would like to show whichcity Fred has consecutively spent the most months in. i.e.
City
Longest Duration (months)
From
To
London
5
June 17

Oct 17

<tbody> </tbody>
 
Upvote 0
I have a similar obstacle - need to count number of consecutive appearances equal to or greater than 6 times. Is it possible to use 'Countif' with "Sumproduct' or "Frequency" conditions? Any help would be much appreciated.
 
Upvote 0
3
31
322
71
72so we need to detect runs of 6 or more
73
74in this case the eight sevens and the nine twos
75
76
772 simple helper columns count the sequences
788yesand give you the run length
91
92a thid helper triggers if run length is 6 or over
933
21
22
23
24
25
26
27
28
299yes
41
42
433

<colgroup><col width="64" span="13" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
You can also get the answer without using helper columns. Try:

=SUM(IF(FREQUENCY(ROW(A2:A27),IF(A1:A26<>A2:A27,ROW(A1:A26)))>=6,1))
confirmed with Control+Shift+Enter.

Change the ranges to match your sheet.
 
Upvote 0
@Folander
To the right of the latest month, I would like to show whichcity Fred has consecutively spent the most months in. i.e.
CityLongest Duration (months)FromTo
London5June 17
Oct 17

<tbody>
</tbody>

I don't know if you still need the formula or if you have figured it out but this should do what you are looking for.

In Cell T2 enter this formula:

=INDEX(B2:S2,MODE(MATCH(B2:S2,B2:S2,0)))

In Cell U2 enter this formula: Remember its an array formula that needs to be enter by pressing Ctrl+Shift+Enter.

{=MAX(FREQUENCY(IF($A2:$S2=T2,COLUMN($A2:$T2)),IF($A2:$S2<>T2,COLUMN($A2:$S2))))}
**This is an array formula and needs to be entered by pressing Ctrl + Shift + Enter**

I don't have time to go through date formula but if no one has answered it for you I will come back when I have time. I hope this helps! :)
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,746
Members
449,050
Latest member
excelknuckles

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