Generate and multiply combinations of fields

Dear all,

I have a table described below with values.  I have inserted column references above to better explain the scenario.

Input/output tables
I'm trying to reconfigure the dataset for each combination of the fields displaying the multiplied the value.
 
The number of combinations will be 2X2X3X2X2 = 36 combinations

C and D are Age fields
E to G are fields related to number of drivers
H and I are use fields
J and K are the number of doors in the vehicle.

i.e. C*E*H*J = 0.24

The output should look like the output above.
Note,  the example is a subset of the results because it is only for 1 age type.
 
 
What is the best approach to achieve this?  As I started working on the database query it became quite tedious I was selecting each combination to calculate the result.  

Thanks.
AndyC1000Asked:
Who is Participating?
 
PatHartmanConnect With a Mentor Commented:
The fact that the output table does not correlate to your description and the input table makes this harder than it needs to be for us to understand. I count 24 combinations
2 x 3 x 2 x 2.

Once the data is denormalized, nothing is ever easy.  You will need 24 queries to produce the requested output and a final union query to bring them all together.  24 selects may be too many for a single union so you might have to break up into several unions so four union queries that union 6 selects each and then a final union to union the 4 unions.

Instead of the unions, you could use append queries to append the 24 sets of data to a temp table and work with that for your reporting.  I tend to not create temp tables unless there is no alternative so try the unions first.

You could of course generate the queries on the fly but the code won't be slick and it will probably end up being simpler to simply use the curmudgeon method and create the 24 d*** queries.
0
 
Jeffrey CoachmanMIS LiasonCommented:
This is all very confusing...
2X2X3X2X2 = 36 combinations
C*E*H*J = 0.24 (only 4 combinations)

It is also not clear what this data represents, ...so an overview of the input data would be helpful.
For example:
Does "Sedan" represent a single car, or all "Sedans?
What is this output trying to display, specifically?
...etc

Can you post the *Full, Exact* results set you need.
(based on all the input data)
...then include a clear mathematical explanation of how each value was calculated...

Perhaps the data structure needs to be re-thought...?
Its just that, ...if all these machinations are needed, then perhaps the design is not optimized for what you are trying to do.

Lets see what the other experts may post...

JeffCoachman
0
 
AndyC1000Author Commented:
Thanks for your comments.

I read through my question and yes its not clear.

I have 2X3X2X2 = 24 combinations.  I mistakenly added the car types in the initial question (which was the extra x2)

The total of the Age fields (Column C and D) = 1, Number of Drivers (Columns E, F, G) = 1, Use fields (H and I) =1  etc. in every row.

C and D are Age fields
E to G are fields related to number of drivers
H and I are use fields
J and K are the number of doors in the vehicle.

Each row in the input table represents 24 profiles (combinations of Age, Drivers, Use and Number doors).

C*E*H*J = 0.24 is 1 of the 24 combinations.

I will create the 24 queries and use union as suggested above.  

The full extract of the result set is:
updated sample input/output
0
 
AndyC1000Author Commented:
Is it possible using Visual Basic ?
0
 
PatHartmanConnect With a Mentor Commented:
Anything is possible using visual basic but you have nothing in the record that would provide a basis for a loop.  If there is no looping, then you'll be hard coding the creation of 24 different queries so you have two bad options.  Pick one.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.