Print Page | Close Window

formula to eliminate year

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21399
Printed Date: 07 May 2024 at 1:24am


Topic: formula to eliminate year
Posted By: kimt
Subject: formula to eliminate year
Date Posted: 24 Mar 2015 at 11:21am
Have a report that lists columnar data by the year and quarter. Would like to eliminate the year if the quarter is > 1.

This is what I have but CR does not like it:

whileprintingrecords; if {Command.fldQuarter} > 1 then {Command.fldyear}= 0 else {Command.fldyear};

Essentially, if quarter > 1 then year = "" else year.

This works: whileprintingrecords; whileprintingrecords; if {Command.fldQuarter} > 1 then totext("") else totext({Command.fldyear},0,"")

Formatting came from yggdrasil on another CRbook forum.

Thanks.



Replies:
Posted By: paulhoving
Date Posted: 25 Mar 2015 at 3:58am
I think this will do:

if {Command.fldQuarter} > 1 then 0 else {Command.fldyear};


Posted By: DBlank
Date Posted: 25 Mar 2015 at 4:34am
are you talking about suppressing the value in a row or changing a header?
your first formula would not work because you cannot set or alter values from your data set (" then {Command.fldyear}= 0").  The one you found that works does so because it is creating a 'new resulting field value' not trying to update your current field(s).
 
if you just wanted to hide the 'Year' field value in the row a simpler approach would be to conditionally suppress the field with  
{Command.fldQuarter} > 1
Or if you only have a 1:1 relationship of Q to a row and you sort from q1 to q4 I would recommend using the field format option of 'suppress if duplicated'. This would do the same thing but show the year value on the first row of a page if teh year was broken across pages.
 
 


Posted By: kimt
Date Posted: 25 Mar 2015 at 6:15am
Thanks for the responses. After struggling for hours trying to write the correct formula with a little help on formatting, suppressing duplicate values took minutes. Guess that's how newbies learn.



Print Page | Close Window