Solved

Generate and multiply combinations of fields

Posted on 2016-07-27
5
69 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
  • 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 34

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 34

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now