Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Merge two formulas Post Reply Post New Topic
Author Message
mac-duff
Newbie
Newbie
Avatar

Joined: 22 Apr 2010
Location: Spain
Online Status: Offline
Posts: 21
Quote mac-duff Replybullet Topic: Merge two formulas
     Posted: 05 May 2010 at 10:54am
Hello,

can please someone tell me how it is possible to merge this two formulas to one?

@TiempoMarcha

If {Produccion.Estado} = "On" then {Produccion.TiempoParo} else 0



@TiempoMarchaDisplay

NumberVar TotalSec := Sum ({@TiempoMarcha}, {CambioTurno.IdEquipo});

NumberVar Hours := Truncate ( TotalSec / 3600);
NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60);
NumberVar Seconds := Remainder (TotalSec , 60) ;

Totext ( Hours, '####') + ':'+ Totext ( Minutes,'00') + ':' + Totext ( Seconds , '00' )



Thanks
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 05 May 2010 at 12:13pm
This should work correctly as is unless {Produccion.Estado} can be null.  In which case you want to change it to something like this:
 
If IsNull({Produccion.Estado}) or {Produccion.Estado} <> "On" then 
  0 
else
{Produccion.TiempoParo}
What is happening that is not working correctly?  If you get an error message, please post it.
 
-Dell


Edited by hilfy - 05 May 2010 at 12:13pm
IP IP Logged
overcharge
Newbie
Newbie
Avatar

Joined: 12 Mar 2010
Location: Malaysia
Online Status: Offline
Posts: 12
Quote overcharge Replybullet Posted: 05 May 2010 at 6:10pm
I did not know this will be work fine, but i think you can give it a try.


NumberVar TotalSec := Sum ({@TiempoMarcha}, {CambioTurno.IdEquipo});

NumberVar Hours := Truncate ( TotalSec / 3600);
NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60);
NumberVar Seconds := Remainder (TotalSec , 60) ;

if {Produccion.Estado}="On" then
Totext ( Hours, '####') + ':'+ Totext ( Minutes,'00') + ':' + Totext ( Seconds , '00' )
else '0'

IP IP Logged
mac-duff
Newbie
Newbie
Avatar

Joined: 22 Apr 2010
Location: Spain
Online Status: Offline
Posts: 21
Quote mac-duff Replybullet Posted: 05 May 2010 at 8:49pm
Hi,
thanks for the answers. I guess u havent understood me correctly. I have this two formulas @TiempoMarcha and @TiempoMarchaDisplay and I call in @TiempoMarchaDisplay the first formula @TiempoMarcha which means I would like to replace in the second formula the statement "@TiempoMarcha" directly with the formula.

If I just place it there the error is that is has to be a field
IP IP Logged
Nissim
Newbie
Newbie


Joined: 04 May 2010
Online Status: Offline
Posts: 18
Quote Nissim Replybullet Posted: 05 May 2010 at 9:24pm
Very helpful. thanks.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 06 May 2010 at 4:09am
Do you have a group on {CambioTurno.IdEquipo}?  If not, that's your problem.
 
Because you need to do the sum, you can't merge the first formula into the second.  Also, the Sum needs to be calculated before the rest of the formula and that doesn't necessarily happen correctly when it's in the same formula as the rest of it.  You can use the WhileReadingRecords and WhilePrintingRecords special clauses to tell Crystal when to process things.  Summary formulas are automatically calculated while reading the data, so I would split the sum out into it's own formula - I'll call it @TotalSeconds wand it looks like this:
  Sum ({@TiempoMarcha}, {CambioTurno.IdEquipo})
 
Then your @TiempoMarchaDisplay formula will be this:
WhilePrintingRecords;
NumberVar Hours := Truncate({@TotalSeconds}/3600);
NumberVar Minutes := Truncate(Remainder({@TotalSeconds}/3600)/60;
NumberVar Seconds := Remainder ({@TotalSeconds}/60);
Totext ( Hours,  '####') + ':'+ Totext ( Minutes,'00') + 
   ':' + Totext ( Seconds , '00' )
 
This way it will be processed after the value for the sum is already known.  I haven't tested this, but it should work.
 
-Dell
IP IP Logged
mac-duff
Newbie
Newbie
Avatar

Joined: 22 Apr 2010
Location: Spain
Online Status: Offline
Posts: 21
Quote mac-duff Replybullet Posted: 10 May 2010 at 11:05am
Hi hilfy,

u tell me exact the same way I wrote in my first post ;) and I wanted to know is it possible to get it into one formula only or is it a constriction of Crystal Reports?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 10 May 2010 at 3:44pm

No, you can't get it into a single formula. And no, what I posted is NOT the exact same way as you first posted - I broke it down one level further.  The sum and the rest of the second formula need to be processed separately so you'll end up with THREE formulas.

You need to move the SUM from your second formula into it's own formula with "WhileReadingRecords;" at the top and the rest of your second formula in its own formula with "WhilePrintingRecords;" at the top.
 
-Dell


Edited by hilfy - 10 May 2010 at 3:45pm
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