Access DSum slowing down query dramatically


In the Access query shown below the DSum is slowing it down from 3 seconds to about 40 seconds. Is there a way to get around this?
SELECT Transactions.SupplierName, Transactions.DocType, Transactions.Reference, Transactions.Amount, Nz(DSum("Amount","Transactions","Reference = '" & [Reference] & "' And DocType = 'Payment'"),0) AS Paid, [Amount]-[Paid] AS Due INTO [Q3 Supplier Invoices ALL]
FROM Transactions
WHERE (((Transactions.DocType)="Invoice"))
ORDER BY Transactions.SupplierName, Transactions.Reference;

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

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

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.

You could try building a separate saved query (as below) that calculates the sums and then using a left join from transactions to the saved query.

Select Reference, sum(Amount) as Paid where DocType = 'Payment'

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
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Excellent. Had done something similar. Its amazing how DSum affects performance
Patrick MatthewsCommented:
All of the domain aggregates are hell on performance.  You should avoid using them unless there is no other way :)
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much. I was trying to be too clever and the performance didn't sit well with the client :)
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:

  <<All of the domain aggregates are hell on performance.  You should avoid using them unless there is no other way :) >>

  This really is not true.  The Domain functions can be as fast or faster then other methods if their used in the way they were intended to be used; queries is NOT one of them.

  They should never be used in a qeury (SQL Statement) as a Domain function in a query is un-optimizable by the query processor.  Poor performance will always result.

  All they represent is a SQL statement anyway, so there is no reason to be using them in a query.

  Domain functions were intended to be used in places where an expression is allowed, but a SQL statement is not (say for a default value property).


Patrick MatthewsCommented:

Quite right.  I meant to say "avoid using them IN QUERIES".


Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thank you for the advice. Much appreciated
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.