Solved

Generate and multiply combinations of fields

Posted on 2016-07-27
5
80 Views
Last Modified: 2016-08-14
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.
0
Comment
Question by:AndyC1000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
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 37

Accepted Solution

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

by:AndyC1000
ID: 41732492
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
 

Author Comment

by:AndyC1000
ID: 41732796
Is it possible using Visual Basic ?
0
 
LVL 37

Assisted Solution

by:PatHartman
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question