Solved

# Generate and multiply combinations of fields

Posted on 2016-07-27
66 Views
Dear all,

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

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.
0
Question by:AndyC1000
• 2
• 2

LVL 74

Expert Comment

ID: 41731434
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

LVL 34

Accepted Solution

PatHartman earned 500 total points
ID: 41731515
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

Author Comment

ID: 41732492

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:
0

Author Comment

ID: 41732796
Is it possible using Visual Basic ?
0

LVL 34

Assisted Solution

PatHartman earned 500 total points
ID: 41733156
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

## Featured Post

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…