MS Access - Overwrite Cell with Value

Hi,
In the attached file, Dept A, B, and C should return the value in the 'Amount' field.  However, Dept D should return a $0 value only when the Serial has an exact match within the dataset (under Dept D).  If Dept D has a Serial without an exact match within the dataset, then Amount * 20% should be returned.  I cannot upload the database due to data sensitivity but the attached file is an example of what I'm looking for (Desired Output field is what the formula should achieve).  Please let me know if there is a formula to achieve this.
New-Microsoft-Excel-Worksheet.xlsx
Wonderwall99Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NerdsOfTechTechnology ScientistCommented:
Basically you would select and unalter records where dept matches A, B, or C,

then UNION  two case JOIN SUBQUERIES for your desired dept D results:


SELECT dept, serial, amount 
FROM tblMain
WHERE dept IN ('a', 'b', 'c')

UNION ALL

SELECT D1.dept, D1.serial, X1.amount
FROM 
(SELECT Serial, 0 as amount
FROM tblMain
WHERE dept = 'd'
GROUP BY serial
HAVING Count(serial) = 1) as X1
LEFT JOIN
(
SELECT serial
FROM tblMain
WHERE dept= 'd'
) as D1
ON X1.serial = D1.serial

UNION ALL

SELECT D2.dept, D2.serial, X2.amount
FROM 
(SELECT serial, (amount*0.20) as amount
FROM tblMain
WHERE dept = 'd'
GROUP BY serial
HAVING Count(serial) > 1) as X2
LEFT JOIN
(
SELECT serial
FROM tblMain
WHERE dept= 'd'
) as D2
ON X2.serial = D2.serial
;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NerdsOfTechTechnology ScientistCommented:
For excel, assuming that the list is sorted by dept and that the range of dept d is adjusted for
$B$7:$B$9
in the formula below, this will provide the desired results as well.

=IF(ISNUMBER(MATCH(A2,{"A","B","C"},0)), C2, IF(COUNTIF($B$7:$B$9,B2)=1, C2*0.2, 0))

Open in new window

New-Microsoft-Excel-Worksheet.xlsx
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.