?
Solved

Compare invoice values from 2 tables with a 5p tolerance

Posted on 2006-10-26
6
Medium Priority
?
212 Views
Last Modified: 2012-08-14
Experts

We are converting from our old system to a new system (rental application) - we are importing contracts from the old to the new - I have to run parallel Invoice runs on both then extract this invoice data from both systems and do a comparison

Due to differences in rounding and VAT calculations I need to compare using a 5p tolerance e.g.

£96.60 - old data
£96.63 - new data

This will be ignored in my query but:

£96.60 - old data
£96.66 - new data

This will flag up a problem in my query

I have a one - to - one exact matching query which I need to modify to cope with this tolerance:

------------------------------------------------------------------
SELECT [OldData].[Trans_date], [OldData].[Ax_acc], [OldData].[Cust_ref], [OldData].[Depot], [OldData].[Cont], [OldData].[Ax_code], [OldData].[SumOfinvl_qty], [OldData].[SumOfAmt], "OldInvoiceData" AS DSet

FROM [OldData] LEFT JOIN  [NewData] ON [OldData].[Cont] = [NewData].[Contract] and [OldData].[Ax_code] = [NewData].[Item] and [OldData].[Trans_Date] = [NewData].[InvDate]

WHERE ((([OldData].[SumOfinvl_qty])<>[NewData].[SumOfQty]))
   OR ((([OldData].[SumOfAmt])<>[NewData].[SumOfLineAmt])) ----------Line to be modified for tolerance
   OR ((([NewData].[Contract]) Is Null))

UNION ALL SELECT [NewData].[InvDate], [NewData].[CustAcct], [NewData].[CustOrder], [NewData].[Depot], [NewData].[Contract], [NewData].[Item], [NewData].[SumOfQty], [NewData].[SumOfLineAmt], "NewInvoiceData" AS DSet

FROM [NewData] LEFT JOIN [OldData] ON [NewData].[Contract] = [OldData].[Cont] and [NewData].[Item] = [OldData].[Ax_code] and [NewData].[InvDate] = [OldData].[Trans_date]

WHERE ((([NewData].[SumOfQty])<>[OldData].[SumOfinvl_qty]))
   OR ((([NewData].[SumOfLineAmt])<>[OldData].[SumOfAmt])) ----------Line to be modified for tolerance
   OR ((([OldData].[Cont]) Is Null))

ORDER BY [OldData].[Cont], DSet;
------------------------------------------------------------------

This Exact match query works perfectly well on like for like data (I manually modified the data to generate some errors to prove this)

The Lines I need to be  modified are highlighted above

I have tried using:

   OR round((([OldData].[SumOfAmt]+0.05)/100)*100)<>round((([NewData].[SumOfLineAmt]+0.05)/100)*100)
and
   OR round((([NewData].[SumOfLineAmt]+0.05)/100)*100)<>round((([OldData].[SumOfAmt]+0.05)/100)*100)

but this doesn't give me anything (this was suggested by somone to try)

Please help as this is now very urgent

If there is any more Info please ask

Thanks in advance

Dave
0
Comment
Question by:SpeedyDirect
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 17813981
try this:

OR (Abs([NewData].[SumOfLineAmt] - [OldData].[SumOfAmt]  <= .05 * [OldData].[SumOfAmt])
0
 
LVL 15

Expert Comment

by:MNelson831
ID: 17813988
I think, if i read this right, that this will get you what you want:

WHERE ([NewData].[SumOfQty]<>[OldData].[SumOfinvl_qty])
   OR (
          ([NewData].[SumOfLineAmt] - [OldData].[SumOfAmt]) > 5
     OR ([OldData].[SumOfAmt] - [NewData].[SumOfLineAmt]) > 5
     )
   OR ([OldData].[Cont] Is Null)
0
 
LVL 61

Expert Comment

by:mbizup
ID: 17813991
Without the extraneous left parenthesis:

OR (Abs[NewData].[SumOfLineAmt] - [OldData].[SumOfAmt]  <= .05 * [OldData].[SumOfAmt])
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:MNelson831
ID: 17814002
Abs for absolute value!  Kudos mbizup I had forgotten that one.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 17814051
Thanks!  
I was reading 5p as 5%.  Rererading this, 5p is pence to UK folks, right?  So if a 5 pence tolerance is needed (not 5% tolerance) the ABS function should look like this (and instead of removing a left parenthesis, I should have added a right one. :-(  )

OR (Abs([NewData].[SumOfLineAmt] - [OldData].[SumOfAmt])  <= .05)
0
 

Author Comment

by:SpeedyDirect
ID: 17817605
Many Thanks to both of you for your responses but:

with a slight modification to mbizup's last comment i.e.

>= 0.06 --------------- not less than

This gives me exactly what I want which is to find all invoices with more than a 5 "pence" difference (these are problems)

So all points to mbizup

Many thanks again

0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question