Merge/Filter 3 matching fields (1 Viewer)

earls

Registered User.
Local time
Today, 10:58
Joined
Mar 27, 2018
Messages
21
I’m trying to create a report summarizing payroll for our drivers. The problem I have is each trip can have multiple drivers (1-3), so being an access novice, I created Driver1, Driver2 and Driver3 (lookup fields within the “trip table”). Now I’m trying to merge all matching drivers (1-3) for totals on a report. i.e. Linda Smith pay total as driver1, driver2 and driver3 roles combine. The two images will explain better (report is what’s desired, it’s from a different database so numbers do not match but layout 1=driver1 2=driver2...)
 

Attachments

  • report.zip
    494.4 KB · Views: 69

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:58
Joined
May 7, 2009
Messages
19,237
create a union query:

select driver1lu as driver, driver1lupay as pay from yourTable
union
select driver2lu as driver, driver2lupay as pay from yourtable where not (driver2lu is null)
union
select driver3lu as driver, driver3lupay as pay from yourtable where not (driver3lu is null);
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:58
Joined
Feb 19, 2013
Messages
16,607
you would be better to normalise your data going forward (and do away with the lookups in your table whilst you are at it).

what you can do in the short term is create a union query to mimic normalised data - something along the lines of

Code:
SELECT "Driver1" as Drivertype, Driver1lu, Driver1luPay
FROM rptDriverpay
UNION ALL SELECT "Driver2", Driver2lu, Driver2luPay
FROM rptDriverpay
UNION ALL SELECT "Driver3", Driver3lu, Driver3luPay
FROM rptDriverpay
 

earls

Registered User.
Local time
Today, 10:58
Joined
Mar 27, 2018
Messages
21
create a union query:

select driver1lu as driver, driver1lupay as pay from yourTable
union
select driver2lu as driver, driver2lupay as pay from yourtable where not (driver2lu is null)
union
select driver3lu as driver, driver3lupay as pay from yourtable where not (driver3lu is null);

Problem solved! Thank You arnelgp! Been racking my brain for hours, your help is greatly appreciated. Got the results I need in the query will finish report tomorrow.
 

Attachments

  • union.PNG
    union.PNG
    12.5 KB · Views: 57

moke123

AWF VIP
Local time
Today, 10:58
Joined
Jan 11, 2013
Messages
3,917
Problem solved!
Maybe for the moment.
You should really take CJ's advice and normalize your data and get rid of the table level lookup fields. You'll be glad you did, in a week or two, when you're looking for another work around.
 

Users who are viewing this thread

Top Bottom