Print Page | Close Window

Difference bewteen two values of same group

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17755
Printed Date: 05 May 2024 at 7:54am


Topic: Difference bewteen two values of same group
Posted By: SachinPawar
Subject: Difference bewteen two values of same group
Date Posted: 14 Oct 2012 at 11:35pm
Hi,
I have following table and I want tocalculate difference between two values but based on the group. I'm displaying the records as latest to oldest.

1    A     4
2    A     5     -1
3    A     2      3
4    B     6
5    B     3      3
6    C     10
7    C     11     -1
8    C     9      2
i.e calculate the difference between first and previous value till value in colB (A,B,C) is same.

Thanks
Sachin



Replies:
Posted By: SachinPawar
Date Posted: 14 Oct 2012 at 11:35pm
Please help me out its very urgent........


Posted By: Sastry
Date Posted: 15 Oct 2012 at 12:04am
HI
 
 
Think your numbers are in a value column then
 
Create the following formula and place in your detail
 
Previous({Value}) -  Value


-------------
Thanks,
Sastry


Posted By: SachinPawar
Date Posted: 15 Oct 2012 at 12:10am
Thanks for your reply.....

That I hv tried but it is calculating the difference for each value......I want it to calculate it based on the group. It is also showing the difference between the last value of A (2) and first value of B(6), which it shows 4.
and it is not that i want.


Posted By: Sastry
Date Posted: 15 Oct 2012 at 12:17am
HI
 
In your example, in A group it is display two values for difference and C group it is displaying 2 difference values.. is that u want or you want to display difference for only last goup item ?


-------------
Thanks,
Sastry


Posted By: SachinPawar
Date Posted: 15 Oct 2012 at 12:19am
I want to calculate the difference for each group seperately.


Posted By: Sastry
Date Posted: 15 Oct 2012 at 12:23am
Hay Sachin..
 
I got it.  Use the same formula whic I told you and also create following formula s :
 
@init
Whileprintingrecords;   //Place this formula in group header
Numbervar x:=0;
 
 
@Disp
Whileprintingrecords; //Place this formula in detail
Numbervar x;
x:=x+1;
 
Now right click on the formula (Previous(value) -Value) and go in format --common--Suppress then give the following condition
 
Whileprintingrecords;  
Numbervar x;
If X = 1 then true else flase
 
 
 


-------------
Thanks,
Sastry


Posted By: SachinPawar
Date Posted: 15 Oct 2012 at 12:31am

Hi,

I'm new to Crystal...

@init - First formula field i need to create and place it in Group header section on the design view


@Disp - - Second formula field i need to create and place it in Detail section on the design view

Not too clear on the below-

Now right click on the formula (Previous(value) -Value) and go in format --common--Suppress then give the following condition

Whileprintingrecords;
Numbervar x;
If X = 1 then true else flase

- First formula field i need to create and place it in Group header section on the design view- First formula field i need to create and place it in Group header section on the design view- Second formula field i need to create and place it in Detail section on the design view- Second formula field i need to create and place it in Detail section on the design viewNot too clear on the below-Not too clear on the below-


Posted By: Sastry
Date Posted: 15 Oct 2012 at 12:54am
I mean..
 
You create one more formula
 
@val
Previous({Value}) - {Valu}  //place this formula in detail to get difference.
 
Now on this formula i.e. (@val) right click ond go in format field --Common--Suppress--Formula editor and give the below formula
 
Whileprintingrecords;
Numbervar x;
If X = 1 then true else flase


-------------
Thanks,
Sastry


Posted By: SachinPawar
Date Posted: 15 Oct 2012 at 1:26am
Thanks for your reply Sir.....it worked.
Just bothering you a little more....

In the same report I have a number of records for each group which have their own IDs and DateTime associated with it....Now I want to have the latest 10 number of records of each group.

If this also works then one of my major report is over...

Thanks in advance.....

Sachin


Posted By: Sastry
Date Posted: 15 Oct 2012 at 1:46am
Hi
 
Go in Report Menu--Record Sort Expert -- and add Datetime field to it and change the order to Descending. so, you get latest record on top in each group.
 
In your report we have already created a formula @disp, using this formula you have to suppres the records.
 
Go In Seciton Expert--Select Detail section--Suppress Formula editor and give the following :
 
Whileprintingrecords;
numbervar x;
if x>10 then true else false


-------------
Thanks,
Sastry


Posted By: SachinPawar
Date Posted: 15 Oct 2012 at 2:51am
Thanks.....



Print Page | Close Window