Access 2010: Calculating difference between detail lines

BobSullivan
3StarLounger
Posts: 235
Joined: 08 Jun 2010, 20:03
Location: Morgantown, PA

Access 2010: Calculating difference between detail lines

Post by BobSullivan »

I have a report that groups information by person, then shows a consistent 5 detail lines. Example:

Bob
A 5%
B 2.5%
C 1.5%

Brian
A 6%
B 4.5%
C 2%


I would like to calculate the difference in the percentages between the detail lines so that the report will read:

Bob
Group Percentage Pct-Change
A 5% 2.5%
B 2.5% 1%
C 1.5%

Brian
A 6% 1.5%
B 4.5% 2.5%
C 2%
Cordially,

Bob Sullivan
Elverson, PA

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Access 2010: Calculating difference between detail lines

Post by HansV »

Is there a field by which the detail records are ordered and that uniquely identifies the detail records?
Best wishes,
Hans

BobSullivan
3StarLounger
Posts: 235
Joined: 08 Jun 2010, 20:03
Location: Morgantown, PA

Re: Access 2010: Calculating difference between detail lines

Post by BobSullivan »

Yes. The record is listed by rating (the letter) Each of the letters represents a detail line in the report, and each of the names represents a group. The report is pulling data from a totals query that groups information by name and by letter.
Cordially,

Bob Sullivan
Elverson, PA

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Access 2010: Calculating difference between detail lines

Post by HansV »

Set the Control Source of the Pct-Change text box to

=[Percentage]-DLookUp("Percentage","MyQuery","[FirstName]=" & Chr(34) & [FirstName] & Chr(34) & " AND [Rating]=" & Chr(34) & Chr(Asc([Rating])+1) & Chr(34))

where MyQuery is the name of the query, and FirstName, Rating and Percentage are the names of the relevant fields.
Best wishes,
Hans