Date difference calculations

Hi I'm trying to summarize the aging of debtors , now below are important fields which i'm using:

- CDate  ( Represent the invoice post date)
- Date () ( Represent the cut off date)
- Debit ( Invoice value or receipts reversal)
- Credit (Receipts & sales returns)

Below is the code I'm using in the Expression builder of the report, by the way I have controls on the page footer as follow:

- 30 Days  60 days  90 days 120 days

Code:    IIF(DateDiff( Cdate,Date()) Between 1 and 30,Sum(([Debit]-[Credit])),Null)

but it is giving me an error ,where I'm going wrong ? this is a sure way of ageing a customer statement without disturbing the detailed report.


Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
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.

Pawan KumarDatabase ExpertCommented:
Please try this -

DateDiff( "d" , DATEVALUE(Cdate), DATEVALUE(Date()) ) >= 1 and DateDiff("d", DATEVALUE(Cdate), DATEVALUE(Date()) ) <= 30,

read more about the datediff from -
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
Cdate is a built-in function in Access, you need to pass the valid parameter to return a valid.

IIF(DateDiff( Cdate,Date()) Between 1 and 30,Sum(([Debit]-[Credit])),Null)

MS Access: CDate Function
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
if "CDate" is a field in your data source, try use bracket to encapsulate it , like:

IIF(DateDiff( [Cdate],Date()) Between 1 and 30,Sum(([Debit]-[Credit])),Null)
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Pawan KumarDatabase ExpertCommented:
Use brackets around cdate if my last comment does not work. Also try not to use language keywords for identifiers.

DateDiff( "d" , DATEVALUE([Cdate]), DATEVALUE(Date()) ) >= 1 and DateDiff("d", DATEVALUE([Cdate]), DATEVALUE(Date()) ) <= 30,
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
That is not it , If I remove the sum it picks the figures, but if return the sum the error comes up
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
how's your report looks like?

it will probably not working in your original function which field: "CDate" will refer to the first record's value.

you may try use a Dsum function instead, like:

=DSum("[Debit]-[Credit]","yourTableOrQuery","DateDiff(""d"",[CDate],Date()) Between 1 And 30")

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
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.