Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Actors Episodes Combination
John S 

3 years ago
I have a database of 1400 episodes, with each episode having a cast of up to 7 actors. In addition, for each episode, at least (one but never more than two) actors are designated as "starring" in that episode. For all episodes, there are 300 actors, with actors often appearing in many episodes. As such, there is a lot of data about combinations of actors.

I'd like to be able to generate stats about these various combinations of actors, for instance: What is the most common combinations of actors for any number of actors (for example, most common two-actor combination, most common three-actor combination, most common four-actor combination, etc.). Another might be most common pair of starring actors. Also, how many unique actual combinations are there, in total?

I'm looking for suggestions about a strategy for approaching the job of generating these stats.

Thanks.
Kevin Yip  @Reply  
     
3 years ago
You may have to use the "brute force" approach and actually count all the permutations for different episodes and different actor combinations.  But with VBA, even brute force can be done quickly because of the speed of computing power.

This is largely a math problem.  As a simple example, an episode with 4 actors, denoted as {1,2,3,4}, has six possible 2-actor combinations: {1,2}, {1,3}, {1,4}, {2,3}, {2,4}, {3,4}.

The math formula is the following.  And this is taught, I believe, in late high-school math classes or early college classes:

If there are N items, the number of combos with k items is:   N! / [k! (N-k)!]

"!" denotes factorial.  For instance, 5!, or 5 factorial, equals 5 x 4 x 3 x 2 x 1 = 120.

So, if an episode has 10 actors, the number of 3-actor combos is:  

     10! / [3! (10-3)!]
   = 10 x 9 x 8 ... x 2 x 1 / (3 x 2 x 1 x 7 x 6 x 5 x 4 x 3 x 2 x 1)
   = 3628800 / (6 x 5040)
   = 120

Using this formula, we can calculate that an episode with 10 actors can have 45 different 2-actor combinations, 120 different 3-actor combos, 210 different 4-actor combos, 252 different 5-actor combos, 210 different 6-actor combos, 120 different 7-actor combos, 45 different 8-actor combos, 10 different 9-actor combos, and, of course, only one 10-actor combo (because there are only 10 actors in the episode).  

Altogether, there are a total of 45+120+210+252+210+120+45+10+1 = 1013 combos for an episode with 10 actors.  Each combo is *one occurrence* of that combo.  You do this exercise for all episodes, count the number of occurrences of every combo, sort the results descendingly, and that's how you find out the combo(s) with the most number of occurrences.

Access doesn't have a factorial function, so you'll have to create your own custom function for it.

If you are familiar with the math above and with VBA, then this should be enough info for you.  If not, I can provide further info later on.
John S OP  @Reply  

3 years ago
Hi Kevin. Very clear explanation. I think I get it. I will give it a try.

Thanks for taking the time to spell it out for me. --John
Kevin Yip  @Reply  
     
3 years ago
I forgot to include the method of actually creating those combinations.  Let's say you have an array of N items:

     Dim arr As Variant
     arr = Array(1, 2, 3, 4, 5, 6, 7, ......)

The VBA code to produce all 2-item, 3-item, and 4-item combos is in the picture below.  Yes, you need to create a separate procedure for each number of item combos in order to simplify the code.  There may be a way do this in one single procedure but it may be complicated.  

My code simply loops through all the items, each loop combining the current item with subsequent ones, until there are no more item left.  It is not terribly ingenious, just another brute-force method.  You need k number of For-Next loops to find all combos with k number of actors.

I use "Debug.Print" to send each combo to the immediate window, for testing purposes.  You can change that to storing the combos in a table.  After finding all combos, run a summation query on the table to count the number of occurrences of each combo.
Kevin Yip  @Reply  
     
3 years ago

John S OP  @Reply  

3 years ago
Thanks, Kevin! Very much appreciated.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 1:16:32 AM. PLT: 0s