Accounts Receivables aging

=IF(AND(TODAY()-$C5<=60,TODAY()-$C5>30),$D5,0)
The above formula is an example of multiple IF statements in excel or multiple criteria where each criteria is joined using AND function. AND function does literally the same thing as the and does in language. So the above formula will be read like this in plain English:
If difference between today’s date and the date in cell C5 is less than or equal to 60 days AND the difference between today’s date and the date in cell C5 is greater than 30 days than fetch the value from cell D5 otherwise put 0.

$C5 represents the filed date
$D5 represents the invoice amount

Now in excel it works very I have tested it , I want to use it in MS Access as well , I have tried like below but it does not work:

=IF(AND(Date()-[MMDate]<=60,Date()-[MMDate]>30),[LineTotal],0)

The above code is supposed to age those amounts in above 30 days and below 60 days

How do I fix it

Sorry to disturb your holiday

Regards

Chris
LVL 2
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can also create a query that shows the Invoice number and number of Days Old and then use that in a second query. To do that, add the Invoice column and then a second aliased column that calculates the DaysOld:

SELECT Invoice, DateDiff("d", YourDateField, Date) AS DaysOld

Save that, then create a second query that includes the first, and Join them on the common field

SELECT * FROM SomeTable INNER JOIN YourSecondQuery ON SomeTable.Invoice=YourSecondQuery.Invoice WHERE DaysOld <=60 AND DaysOld >30

If you want all of them in a single query, create 3 queries (or however many you need) and then combine all of those in a "master" query, using the UNION operator:

SELECT Col1, Col2, Col3, etc  FROM  CurrentQuery UNION SELECT Col1, Col2, Col3, etc  FROM 30DayQuery UNION SELECT Col1, Col2, Col3, etc  FROM 60DayQuery
0
 
als315Commented:
Query could be:
SELECT Sum(LineTotal) AS SumOfLineTotal
FROM YourTable
WHERE (((Date()-[MMDate])>30 And (Date()-[MMDate])<=60));

Open in new window

replace
0
 
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
Still what about >60 days >90 days > 120 days
or simple terms

Why this code does not work in Ms Access

=IF(AND(Date()-[MMDate]<=60,Date()-[MMDate]>30),[LineTotal],0)

Or

=IIF(AND (Datediff("d",[MMDate],Date()))<=60,(Datediff("d",[MMDate],Date())>30),[LineTotal],0)

Could it be the AND operator???????
0
 
als315Commented:
Access syntax differs from Excel. In Access you can use
A AND B
In your samples calculation is made twice, in my sample - only one time. If you have huge tables it may be important. In Access you can select only records, with matched criteria and sum all records.
Your syntax could be:
=IIF((Datediff("d",[MMDate],Date()))<=60 AND (Datediff("d",[MMDate],Date())>30),[LineTotal],0)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.