Skip to main content

Maximum Consecutive wins OR How maximum times, an Event has occurred Consecutively (Using Frequency Function)

























Hi Everyone,
This time, I have come up an excel function which will give you maximum consecutive Wins count for different teams. To be more precise, this article is gonna be about finding maximum consecutively occurring event OR we can say that how maximum times, an event has consecutively occurred. The Function I have used, uses Frequency function in its core. To start with explaining the Win part, I have used following Formula to calculated consecutive wins count for team Say India:-


=MAX(FREQUENCY(IF(($A$1:$A$32=$E$1)*($B$1:$B$32=$D2),ROW($B$1:$B$32)),IF(($A$1:$A$32=$E$1)*($B$1:$B$32<>$D2), ROW($B$1:$B$32))))

I will start by explaining the Frequency function. I have used
IF(($A$1:$A$32=$E$1)*($B$1:$B$32=$D2),ROW($B$1:$B$32)) as Data Array Parameter
AND
IF(($A$1:$A$32=$E$1)*($B$1:$B$32<>$D2),ROW($B$1:$B$32)) as Bin Array Parameters

If I evaluate both parameters simultaneously, It will result in following table.

Data Array Bin Array
FALSE FALSE
FALSE 2
3 FALSE
4 FALSE
-----------------------------> 5 FALSE <-------------------------
Row numbers of India's wins FALSE 6 Row Number of India's Loss
otherwise False. 7 FALSE otherwise False.
8 FALSE
FALSE FALSE
FALSE FALSE
FALSE FALSE
FALSE FALSE
FALSE FALSE
FALSE FALSE
FALSE FALSE
FALSE FALSE
Now before I explain the above two arrays, there are somethings which you should know about Frequency Function.
1. The number of elements in the returned array is one more than the number of elements in bins_array. The extra element in the returned array returns the no. of values above the highest interval. 
2. FREQUENCY ignores blank cells and text in Data Array and Bin Array both.
3. FREQUENCY Function ignores Duplicates in the Bin_Array and treats only first occurrence.
4. FREQUENCY Function returns an array so must be entered as an array formula.

Better if you read the following article which explains about frequency function.

I guess, till now, you should be knowing that Frequency function counts the values in Data array with regard to the Groups OR Bins gets available from Bin Array. The values of Data and Bin array are treated having regard to above conditions. Here is how the above arrays are further processed.

Bins Count of Data Array values fall in Bins
0-2 0 -
2-6 3 (3,4,5)
6-? 2 (7,8)

So the above count conveys that India has won 3 times and 2 times consecutively. So the Maximum would be 3. Using Max Function, we can return the Maximum one that is 3.
So this was an other quality of Frequency function, which I explained with the above example. If you have any query or suggestion, then do comment.

Check the attached example file:-

Regards,
Vikas Gautam

Comments

Popular posts from this blog

Automation:- Sending Invitation to Meeting Using Excel VBA

Hello Everyone, In one of the previous post, I wrote about automating Sending Emails using Excel VBA. This time I have come up with a pretty similar code. The code below sends Outlook Meeting Invitations to recipients on one click. here is the Code:- Sub Send_Invite_Auto() Dim olApp As Outlook.Application Dim olApt As AppointmentItem Set olApp = New Outlook.Application 'Creating Outlook Session Set olApt = olApp.CreateItem(olAppointmentItem) 'Creating an Appointment With olApt .Subject = "Enter the subject here." 'Subject .Start = DateAdd("d", 5, Now) 'Enter Date + Time here. .Recipients.Add ("example@gmail.com") 'Recipient Name, Alias, or any other Attribute. .MeetingStatus = olMeeting 'olAppointmentItem with Meeting status olMeeting 'becom

Highlighting Duplicates across multiple sheets

Hi One and All, This time I have come up with some conditional formatting stuff. The aim is to highlight the duplicates across multiple sheets and with in the sheet as well. Assumptions:- 1. I am assuming that sheet names goes on like sheet1, sheet2, sheet3.... 2. The Target Column No. is same in all the sheets. I mean, as in the attached example, its Column A which is being targeted in both sheets.

Making Password Protected PDFs using Excel Vba and PDFtk Tool

Hi Everyone, This time, I have come up a VBA Code to generate Password protected PDFs using Excel. Actually, Excel Vba has .ExportAsFixedFormat Method to generate PDFs but this hasn't any Parameter which takes password to protect the PDFs. So I have used PDFtk Tool which provide Command Line Interface to make PDFs protected using Password. Actually, You can do various things using PDFtk Tool command line varying from creating, merging, Protecting and many other. So Download the PDFtk Tool from the following link:- Download PDFtk Tookit Here are the Steps:- 1. Install the PDFtk Toolkit. 2. Use the following code to Print or Export the Activesheet with a password.