Access query to pull maximum percentage, with a couple of catches...
Posted on 2011-03-07
Hello - I'm working with a spreadsheet containing data for corporate construction projects
Each project can have up to 7 business units that will be billed back for the project costs, at a particular percentage, which might be equal splits, or not
These are entered just like you would expect in the spreadsheet:
Project ID, (...various project info fields...), BU Number1, BU Percent1, BU Number2, BU Percent2, BU Number3, BU Percent3, etc...
The project managers just enter them (in no meaningful, reliable order) in 7 sets of 2 columns on the spreadsheet
When I import this spreadsheet into Access, I load the project header info into a parent table, and then make a series of 7 passes to load the the bill-back entries into a child table
The project bill-back table looks like this:
Project Header ID - parent key back to the projects headers table
Bill Back entry # - the ordinal number of the bill-back entry field pairs (BU Number1 and BU Percent1 are loaded in with an entry # of "1", etc...)
Business Unit ID - ID number of the BU
Business Unit Pct - pct of costs this BU will be billed back for
They want one report that will display, by project, the business unit with the highest bill-back percentage
If 2 or more BU's have the same bill-back percentage, display the BU with the lowest entry #
I have racked my brains, but can't come up with the SQL to get me there in one pass
or even 2... or 3... :-(
Anybody done something like this?