Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: formulas Post Reply Post New Topic
Author Message
aftershokk
Newbie
Newbie


Joined: 06 Apr 2010
Online Status: Offline
Posts: 11
Quote aftershokk Replybullet Topic: formulas
    Posted: 24 Aug 2011 at 2:50am
I am not A frequent crystal user but trying to get better.

I have a report which groups on year then type of test with a count of cases.

example:

2010 (group)
MRI (group)
303 cases (sum)

2011 (group)
MRI (group)
456 cases (sum)

For the life of me I cannot figure out how to get a variance
456 cases / 303 cases

Please help!


IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 24 Aug 2011 at 3:24am
well, there is just one test, it would be easy...
create a formula for the sum, in it create a shared variable, assign it the value of the sum, then display the sum.  In the next year, do the same thing and then you can display your variance but.... I'm betting that there is more than 1 test in a year.
 
as an outline, here's what I do
create a string that holds the years you are testing (I am guessing that there may be more than 2, or a new/old test that only occurs in year)
create a string that holds the year, test, cases.  When you want the variance you find the parts of the string and display them.  An array would be easier, but in CR you only have 1-D arrays, so you would need several arrays.
 
I was thinking something like this. I would probably put it in 2nd group footer:
 
shared stringvar sYears;  //may not be needed
shared stringvar results;
local numbervar cases := count({table.field}, {group.criteria});
 
if results = "" then results := "|";
results := results + totext({table.yearField},0,"") + "^" + {table.testFeild} + "@" + totext(cases,0,"") + "|" ;
 
cases;  //display the sum
 
now when you want to get the variance, you have to know 2 things, what year and what test, if you want all of them you will just want to format your textbox to be a) wide enough and b) to grow
 
you would search for the year/test combo
shared stringvar results;
local numbervar year1;
local numbervar year2;
local numbervar index;
local numbervar index2;
local stringvar search;
 
// say looking for a year/test
search:="|" + totext(yearWanted, 0,"") +"^" + testWanted+"@";
index := instr(results, search);
if index = 0 then
  year1 := 0;
else(
  index2 = instr(index + 1,results,"|");
  if index2 = 0 then index2 = len(results) + 1;
  year1 := val(mid(results, index + len(search), index2 - len(search) - 1);
);
 
search:="|" + totext(yearWanted-1, 0,"") +"^" + testWanted+"@";
index := instr(results, search);
if index = 0 then
   year2 := 0;
else(
   index2 = instr(index + 1,results,"|");
   if index2 = 0 then index2 = len(results) + 1;
   year2 := val(mid(results, index + len(search), index2 - len(search) - 1);
);
 
if year1 = 0 or year2 = 0 then
  0;  //variance ???  or whatever value you want
else
  year1 / year2;
 
 
didn't think it would be this long.
 
you can of course modify it as needed, but hopefully it is a path.
 
 
 
IP IP Logged
aftershokk
Newbie
Newbie


Joined: 06 Apr 2010
Online Status: Offline
Posts: 11
Quote aftershokk Replybullet Posted: 24 Aug 2011 at 3:53am
sorry but I hit report post in error, how do I undo?
IP IP Logged
aftershokk
Newbie
Newbie


Joined: 06 Apr 2010
Online Status: Offline
Posts: 11
Quote aftershokk Replybullet Posted: 24 Aug 2011 at 3:56am
wow this is crazy, all of this code just to divide 2 values??? cognos, Business objects, excel and even SQL can handle this much easier...

I did create 2 formulas one for 2010 (if field = 2010 then sum else 0)
one for 2011 (if field = 2011 then sum else 0)

but when I try to divide the formulas I get divide by zero error
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 24 Aug 2011 at 11:52am
if you just want to sum up all in year1 and divide by the sum of year2, that's easy.
 
what I thought you wanted was to sum up x different tests in y different years and display the variance for each one.  So this solution is more complex, as I envisioned a more complex report...  to sum up 1 year and compare to the next year, irrespective of test
in the group footer:
shared numbervar lastyear;
local numbervar thisyear := count({table.field}, {groupCondition});
 
if lastyear <> 0 then
  lastyear / thisyear;
 
thisyear
 
 
as for others doing more simply...if you can do it those, you can do it in CR. Just use the same logic.  All reporting systems are the same, CR/SSRS/DevExpress/SQL all operate the same way, in the most basic of sense. It is all group theory and determining what is in the group and what you want to do to it.


Edited by lockwelle - 24 Aug 2011 at 11:56am
IP IP Logged
aftershokk
Newbie
Newbie


Joined: 06 Apr 2010
Online Status: Offline
Posts: 11
Quote aftershokk Replybullet Posted: 30 Aug 2011 at 4:22am
thanks
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.