Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Running Total - Sort order messing things up Post Reply Post New Topic
Author Message
JDuncan
Newbie
Newbie


Joined: 03 Sep 2009
Online Status: Offline
Posts: 2
Quote JDuncan Replybullet Topic: Running Total - Sort order messing things up
     Posted: 03 Sep 2009 at 9:45am
Hi.  I'm trying to create a report that shows details of orders.  I would like a running total that shows how much stock I will have remaining for a given part after each order.  If I order the report by Part_Number then I can make this work (I have a running total for Quantity_Demanded and subtract this from my Total_Stock).
However I would like the report to be first ordered by Order_Date and this breaks the running total.

I think what I'm asking is, is it possible to create a running total that is based on sorting the data in one way, but actually display this data in a different way.

Might something to do with variables be the\an answer?
I've been hacking around with Crystal Reports for a few years but I've never managed to get my head round variables, maybe now is the time.  If I could create variables dynamically, that is one to do a running total for each Part_No that appears then I think I'd have the answer.  However I don't know if this is even possible, far less have any idea about the syntax.

Any help or suggestions greatly appreciated. 

TIA /James
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 04 Sep 2009 at 6:37am
you might be able to do it in a shared array, or a pair as I don't know if Crystal goes beyond 1 dimension...I don't use arrays much in Crystal as I can't 'see' the data.
 
What I will often do for a case like this is to create a string variable and delimit it.  Maybe use pipes for the part_number and carats for the quantity ie |part1^quant1|part2^quant2|.  This you can build on the fly, as you are adding to a string if the part doesn't exist and updating it if it does.
 
for finding if a part exists: instr(PartCount, "|"+{table.part})   you might need to trim the part number so that it matches the string, all depends on how you build the string.
 
variables are pretty easy, in this case, you will never be displaying the variable, just a part of it, and you never be resetting so there is just increment and partial display:
 
increment is probably harder, something like:
shared stringvar PartCount;
local numbervar iIndex := instr(PartCount, "|"+{table.partNumber})
local numbervar carat;
local numbervar inv;
 
if iIndex = 0 then(
 PartCount := PartCount + "|" + {table.partNumber}+"^"+totext(inventoryAmount)+"|";
inv:=(inventoryAmount)
)
else(
 carat := instr(iIndex, PartCount, "^");
 inv :=val(mid(PartCount, carat +1, instr(iIndex+1, PartCount, "|")-1));
 inv := inv+(inventoryAmount);
 PartCount := Left(PartCount, carat) + totext(inv) + mid(PartCount,instr(iIndex+1, PartCount, "|"))
);
 
inv
 
displaying is just parsing the string correctly(and you might not need to do it as inv would be the running total, you can modify the first half of the if to set a value to inv then at the end display inv...mods in red
 
this should work, at least it is good start.
 
HTH
IP IP Logged
JDuncan
Newbie
Newbie


Joined: 03 Sep 2009
Online Status: Offline
Posts: 2
Quote JDuncan Replybullet Posted: 04 Sep 2009 at 6:59am
Thankyou very much for your reply.  I will go through it and see what I can learn and apply.
IP IP Logged
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