Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same Calculation Different Numbers

Status
Not open for further replies.

chevyimpala

Programmer
Dec 19, 2003
37
US
Okay the problem is that I have 2 reports. One called Currency, and another called Performance. Each report has a calculation for a column named Unreal like this:

Unreal: IIf([Curr]="EUR" Or [Curr]="GBP",[Size]*-1*[Rate]+([Size]*[Revalrate]),IIf([Curr]="CHF" Or [Curr]="JPY",[Size]*-1/[Rate]+([Size]/[Revalrate]),IIf([Curr]="EUR/JPY" Or [Curr]="EUR/GBP",[Size]*([Revalrate]-[Rate])/[Rate])))

and each report takes data from the same table. Now here is where the problem inlies. When I run the Currency report I get a sum of this column as -1,412,023 (the correct amount), however when I run the performance report I get a sum of the column that reads 142,835.

I have been stairing at this problem for 2 hours and I cant figure out why it is giving me 2 different numbers in each report. If anyone can help I would be greatful

THX
 
I'm not sure why you might be getting two different values. Is the data source property of these two reports the table, or some SQL statement (or query) based on the table? You might want to try saving the data sources as two queries, and then compare their SQL values to look for any subtle differences. Also, check the calculated field for any subtle differences between the two reports.

You might also want to try using different data values to see how the two reports respond to other data.

It's impossible (in theory at least) for Access to be performing the same calculation on the same data and consistently get two different values. I'm guessing that you're overlooking something small that turns in to something large when the entire data set is examined.

Good luck. I hope this helps point you towards the solution.
 
How are ya chevyimpala . . . .

First there's an error in the last IIF statement. You have:

IIf([Curr]="EUR/JPY" Or [Curr]="EUR/GBP",[Size]*([Revalrate]-[Rate])/[Rate])

The return for a failing condition is missing.

Both returns for an IIF have to be supplied. I'm suprised you did'nt get an syntax error here?!

Fix this and it should work. Your failure is a precursor to the missing return!

TheAceMan [wiggle]

 
TheAceMan1
Don't think that's the problem. The FALSE condition in the first IIF is another IIF (i.e. "IIf([Curr]="CHF" Or [Curr]="JPY" ...") which is acceptable.

My suspicion is (since the problem is in a SUM calculation) that the two queries are retrieving different records and therefore summing different values.

Can you post your SQL?
 
Here is my sql code for both reports

Currency:

SELECT TBLFund.Curr, TBLFund.VD, TBLFund.Date, TBLFund.Account, TBLFund.Size, TBLFund.Rate, TBLFund.Revalrate, IIf([Curr]="EUR" Or [Curr]="GBP" Or [Curr]="EUR/JPY" Or [Curr]="EUR/GBP",[Size]*-1*[Rate],IIf([Curr]="CHF" Or [Curr]="JPY",[Size]*-1/[Rate])) AS Net, IIf([Curr]="EUR" Or [Curr]="GBP",[Size]*-1*[Rate]+([Size]*[Revalrate]),IIf([Curr]="CHF" Or [Curr]="JPY",[Size]*-1/[Rate]+([Size]/[Revalrate]),IIf([Curr]="EUR/JPY" Or [Curr]="EUR/GBP",[Size]*([Revalrate]-[Rate])/[Rate]))) AS Unreal, TBLFund.CHECK
FROM TBLFund
WHERE (((TBLFund.Curr)=[Enter in Currency]))
ORDER BY TBLFund.VD, TBLFund.Account;

Performance:

SELECT DISTINCTROW TBLFund.Curr, IIf([Current Pos]<>0,0,Sum(IIf([Curr]=&quot;EUR&quot; Or [Curr]=&quot;GBP&quot; Or [Curr]=&quot;EUR/JPY&quot; Or [Curr]=&quot;EUR/GBP&quot;,[Size]*-1*[Rate],IIf([Curr]=&quot;CHF&quot; Or [Curr]=&quot;JPY&quot;,[Size]*-1/[Rate])))) AS [Sum Of Size], IIf([Current Pos]=0,0,Sum(IIf([Curr]=&quot;EUR&quot; Or [Curr]=&quot;GBP&quot;,[Size]*-1*[Rate]+([Size]*[Revalrate]),IIf([Curr]=&quot;CHF&quot; Or [Curr]=&quot;JPY&quot;,[Size]*-1/[Rate]+([Size]/[Revalrate]),IIf([Curr]=&quot;EUR/JPY&quot; Or [Curr]=&quot;EUR/GBP&quot;,[Size]*([Revalrate]-[Rate])/[Rate]))))) AS Unreal, Sum(TBLFund.Size) AS [Current Pos], TBLFund.Revalrate, SetupFund.BeginMon, SetupFund.MTM, TBLFund.Account
FROM TBLFund, SetupFund
GROUP BY TBLFund.Curr, TBLFund.Revalrate, SetupFund.BeginMon, SetupFund.MTM, TBLFund.Account;

Maybe you can see the problem!!!
 
Roger that Golom! . . . . .

But all IIF's need to be complete with both true and false parts supplied. Every time I've forgotton one I've always raised a syntax error or missing parenthesis notice(to my knowledge).

As a matter of troubleshooting this is the first thing I would fix. Can't take a stab at it if the code is already faulty? Besides could be asking for trouble later.

In any case I'm interested in what happens after its fixed. I'm betting the problem will be more revealing. You know how Access is, sometimes it can be funny that way. Just wanna know what comes up with clean code.

TheAceMan [wiggle]

 
In the Currency Query you are retrieving records that satisfy:
Code:
FROM TBLFund
WHERE (((TBLFund.Curr)=[Enter in Currency]))
and in Performance they satisfy
Code:
FROM TBLFund, SetupFund
GROUP BY TBLFund.Curr, TBLFund.Revalrate, SetupFund.BeginMon, SetupFund.MTM, TBLFund.Account
(i.e. a cross-join of the two tables.)

You are not restricting the records in &quot;Performance&quot; to a particular currency as you are in the &quot;Currency&quot; query and NULLS in one or both tables in the grouped fields may be dropping records in the GROUP BY.


BTW: The DISTINCTROW doesn't do anything for you. As Access documentation says

DISTINCTROW has an effect only when you select fields from some, but not all, of the tables used in the query.

 
Golom . . . .

If you notice there are three IIF's. Its the last nested IIF I'm refering to.

TheAceMan [wiggle]

 
Golom,

What I dont understand is if I sum the Unreal in the currency report and I get 1,412,038, why is it what I use the same format for the Performance query and I do a sum on the report I get 425,803.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top