You are on page 1of 7

Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.

com
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Report Formulas Cheat Sheets
by Crystal Reports Online Training
NOTICE OF RIGHTS
All rights reserved. No part of this book ma be reprod!"ed# stored i$ a retrieval sstem or tra$smitted i$ a$
form or b a$ mea$s# %itho!t the prior %ritte$ permissio$ of the p!blisher# e&"ept i$ the "ase of brief
'!otatio$s embodied i$ "riti"al arti"les or revie%s.
NOTICE OF (IA)I(IT*
The a!thor a$d p!blisher have made ever effort to e$s!re the a""!ra" of the i$formatio$ herei$. Ho%ever#
the i$formatio$ "o$tai$ed i$ this book is sold %itho!t %arra$t# either e&press or implied. Neither the a!thors
a$d Crstal Reports O$li$e Trai$i$g# $or its dealers or distrib!tors# %ill be held liable for a$ damages
"a!sed either dire"tl or i$dire"tl b the i$str!"tio$s "o$tai$ed i$ this book# or b the soft%are or hard%are
prod!"ts des"ribed herei$.
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
String Functions
String Analysis Functions
Function Name Description
AscW(str) Returns the ASCII alue o! a
character.
ChrW(al) Returns the character
e"uialent o! an ASCII alue.
#en(str) $ets the number o! characters
in the string.
Is%umeric(str) Tells i! the string can be
properly conerte& to a
number.
InStr(start'str(' str)'
compare)
*etermines i! str) is a sub+
string o! str(. The start an&
compare arguments are both
optional.
InStrRe(start'str('
str)' compare)
Same as InStr() e,cept that it
starts at the en& o! the string
an& searches towar&s the
beginning.
StrCmp(str(' str)'
compare)
Compares two strings to each
other.The compare argument
is optional.
-al(str) Returns the numeric
e"uialent o! the string.
The StrCmp() !unction returns a alue base&
upon how the two strings compare to each
other. .ust li/e the Instr() !unctions' you can
pass a compare argument to set case
sensitiity.
StrCmp(str1, str2) Return Values
Return Value Description
+( str( 0 str)
1 str( 2 str)
( str( 3 str)
String Parsing Functions
Function
Name
Description
Trim(str) Trim the spaces !rom both si&es o! a
string.
#Trim(str) Trim the spaces !rom the le!t si&e o!
a string.
RTrim(str) Trim the spaces !rom the right si&e
o! a string.
4i&(str' start'
length)
Return a gien number o! characters
starting at a speci!ie& position. The
start an& length arguments are
optional.
#e!t(str'length) Return a gien number o! characters
starting with the le!tmost character.
Right(str'
length)
Return a gien number o! characters
starting with the rightmost character.
The Trim() !unction &eletes all e,traneous
spaces !rom either si&e o! the string' &epen&ing
on which !unction you call. The 4i&()' #e!t()'
an& Right() !unctions return a partial string
where the number o! characters returne& is
base& on the length argument. I! you &on5t
pass a length argument to the 4i&() !unction' it
returns all characters starting with the !irst one
you speci!ie&.
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
String Manipulation Functions
It is common !or a string to be mo&i!ie& be!ore
it is &isplaye& on a report. This can consist o!
re!ormatting the string or een 6oining the
&i!!erent elements o! an array into a single
string.
String Manipulation Functions
Function Name Description
7' 8 Concatenate(combine) two
strings into a single string.
Filter(str'!in&' inclu&e'
compare)
Search an array o! strings
!or a sub+string an& return
an array matching the
criteria.
Replace(str'!in&'
replace'start'
count' compare)
Fin& a string an& replace it
with another string. The
arguments start, count an&
compare are all optional.
StrReerse(str) Reerse the or&er o! all
characters in the string.
ReplicateString(str'
copies)
Returns multiple copies o! a
string.
Space(al) Returns the speci!ie&
number o! spaces as a single
string.
.oin(list' &elimiter) .oin an array o! strings into
one string an& separatethem
with the speci!ie& &elimiter.
Split(str'&elimiter'
count' compare)
Split a single string into an
array o! strings base& upon
the speci!ie& &elimiter.The
arguments count an&
compare are optional.
9icture(str'template) Formats the characters in a
string onto a template.
The 7 or 8 is use& between two string
ariables (or !iel&s) to combine them into a
single string. An e,ample is:
{Customer.LastName} & ", " & {Customer.FirstName};
Although you can use 8 to concatenatestrings'
it is recommen&e& that you use 7 because it is
most commonly recogni;e& as the stan&ar&
operator !or concatenating strings. <sing 8 can
be con!use& with arithmetic !unctions.
An easy way to insert the "uote into a string is
to use the ChrW(=>) !unction. This returns the
"uote literal an& it is much easier to rea&.
// Display "Ben Hur"
Chrw(34) & "Ben Hur" & Chrw(34)
The Filter() !unction searches an array o!
strings !or a matching sub+string. It returns an
array o! all the strings that hae that sub+string
in them. The !irst argument is the string array
an& the secon& argument is the sub+string to
search !or. The Filter() !unction has an optional
inclu&e argument that tells the !unction to
return an array o! strings that &on5t match the
sub+string. ?ssentially' this woul& be the same
as saying that it returns all strings where the
InStr() !unction returns a ;ero.
The Replace() !unction searches !or a sub+
string within another string' an& i! it !in&s it'
then it replaces it with the new string. It uses
an a&&itional optional argument calle& count.
The count argument lets you limit how many
string replacements are &one. I! you pass a
number !or this argument' then the number o!
replacements &one cannot e,cee& that alue. I!
you &on5t pass a alue !or this argument' then
all the sub+strings are replace&.
The Split() an& .oin() !unctions wor/ together
nicely. The Split() !unction ta/es a string an&
splits it into a string array. The string is
separate& base& upon a character you pass to
the !unction. This is typically a comma' but it
can be anything you nee& it to be. Splitting the
string apart ma/es it is easy to wor/ on the
in&ii&ual strings. A!ter you are &one ma/ing
any necessary changes to the in&ii&ual
strings' you can combine them bac/ into one
string using the .oin() !unction. @ow
conenientA
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Converting Data Types
?en though the &ata types in Crystal synta,
are !airly simple' you still hae to ma/e sure
that they are compatible. Fortunately' this
shoul&n5t cause problems because there are
!unctions to conert between the &i!!erent &ata
types.
Data Conversion Functions
Conversion Function Description
CBool(number)'
CBool(currency)
Conert to Boolean.
CCur(number)'
CCur(string)
Conert to Currency.
C*bl(currency)'
C*bl(string)'
C*bl(boolean)
Conert to %umber.
?"uialent to
To%umber(). See the
section CFormatting
-alues !or OutputD.
CStr() Conert to String.
?"uialent to ToTe,t().
C*ate(string)' C*ate(year'
month' &ay)'
C*ate(*ateTime)
Conert to *ate.
CTime(string)' CTime(hour'
min' sec)' C*ate(*ateTime)
Conert to Time.
C*ateTime(string)'
C*ateTime(&ate)'
C*ateTime(&ate'time)'
C*ateTime(year'month'
&ay)
Conert to *ateTime.
C*ateTime(year'month'
&ay' hour'
min' sec)
Conert to *ateTime.
To%umber(string)'
To%umber(Boolean)
Conert to a %umber.
ToTe,t() Conert to String. Same
as CStr().
Is*ate(string)' IsTIme()'
Is*ateTime()
Test a string !or being a
ali& &ateEtime.
ToWor&s(number)'
ToWor&s(number'&ecimals)
Conert a number to its
wor& e"uialent.
The CBool() !unction ta/es a number or
currency alue an& conerts it to Boolean True
or False. Any non+;ero alue is conerte& to
True an& ;ero is conerte& to False. When it is
&isplaye& on a report' it prints the wor&s
CTrueD or CFalseD.
The CCur() !unction ta/es a number or string
an& conerts it to the Currency &ata type.
When conerting a string' it can hae
!ormatting characters in it (CFD' C'D' etc.) an& it
will still be conerte& properly.
The C*bl() an& To%umber() !unctions are
e"uialent. 9ass each a alue an& it gets
conerte& to a number.
The C*ate()' CTime() an& C*ateTime() are all
similar. 9ass them a string an& it gets
conerte& to the proper &ata type. The string
parser !or this !unction is ery sophisticate&.It
lets you pass strings as &ierse as C.an (>'
(>>(D' CGE)HE(>>ID an& C)11)' Feb 1JD. Kou
can also pass numbers as in&ii&ual arguments
!or representing the &i!!erent parts o! a &ate
an& time. See Table H+G !or the arious
argument options.
When conerting a string to a &ate or number'
you run the ris/ o! raising an error i! the string
isn5t in the e,pecte& !ormat.Kou can aoi& this
by testing the strings ali&ity be!ore conerting
it. The Is*ate() an& Is%umber() !unctions &o
this !or you. They return True i! the string can
be properly conerte&.I! not' they return False.
For e,ample' here is a !unction that conerts a
string to a &ate'but only i! it is a ali& &ate.
If IsDate({Invoice.ExpirationDate}) Then
CDate({Invoice.ExpirationDate});
The ToWor&s() !unction ta/es a number an&
conerts it to its e"uialent in wor&s. This is
similar to writing a &ollar amount on a chec/
an& then spelling out the !ull amount in wor&s.
It prints the &ecimal portion as CLLE(11D. Kou
can set the number o! &ecimals it &isplays by
passing a number to the secon& argument'
which is optional. %otice in the secon&
e,ample how it only &isplays one &ecimal
place an& it roun&s it up to the ne,t higher
number.
//Demonstrate the ToWords() formula
ToWords(123.45); //Result is "one hundred twenty-
three 45 / 100"
ToWords(123.45,1); //Result is "one hundred twenty-
three and 5 / 100"
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Formatting Values for Output
The CStr() !unction is passe& the alue to
!ormat as the !irst argument an& a !ormatting
string as the secon& argument.
CStr() Formatting Caracters
Format Description
L <se with !ormatting numbers. ?ach
instance o! it allocates space !or a
single &igit. I! the number isn5t ery
large' the remaining part is !ille& with
spaces. I! the number is too large' the
integer part is still !ully &isplaye&.
<nuse& &igits a!ter the &ecimal are
;ero !ille&.
1 <se with !ormatting numbers. I! the
number isn5t large enough' it is
pa&&e& with ;eros. I! the number is
too large' the integer part will still be
!ully &isplaye&. <nuse& &igits a!ter
the &ecimal are ;ero !ille&.
' <se with !ormatting numbers to
&esignate the thousan& separators.
. <se with !ormatting numbers to
&esignate the &ecimal separator.
*' 4 *ay an& month as a number (without
a lea&ing ;ero).
&&' 44' yy *ay' month an& year as a two &igit
number (with a lea&ing ;ero when
necessary).
&&&' 444 *ay an& month as a three letter
abbreiation.
&&&&' 4444'
yyyy
*ay' month an& year !ully spelle&
out.
@' m' s Time portions (() hour) as a number
without a lea&ing ;ero.
hh' mm' ss Time portions (() hour) as a two
&igit number (with a lea&ing ;ero
when necessary).
@' @@ Show hours using a )J hour cloc/
(military time).
T Single character representation o!
A4E94.
TT Two characterrepresentation o!
A4E94.
CStr() !"ample #utput
# CStr() Output
( CStr(()=J' )) (')=J.11
) CStr(()=J.GHM' )) (')=J.GM
= CStr(()=J.GHM' CLD) ()=J
J CStr(()=J.GHM' C1D) ()=J
G CStr(()=J' C1.LLD) ()=J.11
H CStr(()=J' C1.11D) ()=J.11
M CStr(()=J.GHM' CL.LLD) ()=J.GM
I CStr(()=J.GHM' C1.11D) ()=J.GM
> CStr(()=J.GHM' CLLLLLD) ()=J
(1 CStr(()=J.GHM' C11111D) 1()=J
(( CStr(L(E)E)11= 1J:1G:1H
amL'
C&E4Eyy @EmEstD)
)E(E1= J: G: H A
() CStr(L(E)E)11= 1J:1G:1H
pmL'
C&&E44Eyyyy @@EmmEss
ttD)
1(E1)E)11= (H:1G:1H
A4
(= CStr(L(E)E)11= 1J:1G:1H
amL'
C&&E44Eyyyy hhEmmEss
ttD)
1(E1)E)11= 1J:1G:1H
A4
(J CStr(L=:)1 94L'
C@@:mmD)
(G:)1
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Date and Time Functions
Crystal Reports gies you a plethora o! &ate
an& time relate& !unctions to utili;e. Kou can
also combine &i!!erent !unctions together to
createery power!ul &ate calculations.
Date an$ %ime Functions
Function Name Description
Current*ate'CurrentTime'
Current*ateTime'9rint*ate'
9rintTime
Returns the current
&ate an&Eortime.
*ata*ate' *ataTime The &ate an& time that
the report &ata was last
re!reshe&.
*ateSerial(year'month' &ay)'
*ateTime(hour'minute'
secon&)
Returns a &ate or time.
*ateA&&(interal' number'
&ate)
Increases the &ate by a
certain interal.
*ate*i!!(interal' start&ate'
en&&ate'!irst&ayo!wee/)
Fin& the &i!!erence
between two &ates.
*ate9art(interal' &ate'
!irst&ayo!wee/'
!irstwee/o!year)
Return a number
representing the current
interal o! a &ate.
*ay(&ate) Return the &ay
component as a
number.
@our(time)' Secon&(time)'
4inute(time)
Return the time relate&
components.
4onth(&ate) Return the month
component as a
number.
4onth%ame(&ate'
abbreiate)
Return the !ull month
name. When the secon&
argument is True' it
returns the =+letter
abbreiation.
Time(time)'Time(hour'min'
sec)' Time-alue(time)
Return a Time &ata
type gien a string
(N((:G>:11 94N) or
numeric time().
Timer The number o! secon&s
since mi&night.
*ayO!Wee/(&ate'
!irst&ayo!wee/)
Return a number
representing the &ay o!
the wee/.
Wee/&ay%ame(wee/&ay'
abbreiate'!irst&ayo!wee/)
Return the !ull wee/
name. Return the =+
letterabbreiation i!
the secon& argument is
True.
Kear(&ate) Return the year
component as a
number.
&nterval Strings 'or DateA$$(), DateDi''() an$
DatePart()
String Description
yyyy Kear
O Ouarter
4 4onth (( through ())
ww Wee/ o! the year (( through G=)
W *ay o! the wee/ (( through M)
K *ay o! year (( through =HH)
* *ay part o! the &ate (( through =()
@ @our
% 4inute
S Secon&
Printing the Current Date and Time
There are !ie !unctions which return a report5s
&ate an& time. The !unctions Current*ateTime'
Current*ate' CurrentTime' 9rint*ate' an&
9rintTime all return the &ate or time that the
report was printe&. Although the !unctions
Current,,, an& 9rint,,, hae &i!!erent names'
they are synonymous with each other.
The !unctions *ata*ate an& *ataTime return
the &ate an& time that the report &ata was last
re!reshe&. I! a report has the Sae *ata With
Report option turne& on' this will tell you how
current the &ata is.
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Reporting Formulas Cheat Sheet by www.CrystalReportsOnlineTraining.com
Special Crystal Reports Training Invitation
The Crstal Reports O$li$e Trai$i$g program "o$sists of over 1,500 online pages of i$+depth
i$str!"tio$ o$ !si$g Crstal Reports a$d Crstal Reports for .NET. ,a$ "hapters i$"l!de both
begi$$er a$d adva$"ed t!torials.
-hether o! are lear$i$g to b!ild o!r first report or a "omple& "ross+tab report# the t!torials
%alk o! thro!gh ea"h step of the %a.
I$"l!ded %ith the three best-selling boos are vi!eo tutorials. -e k$o% that some people
lear$ better b %at"hi$g rather tha$ readi$g# a$d the videos %alk o! thro!gh the steps o!
$eed to b!ild reports.
As a val!e added servi"e# there is a members-only "orum %here o! "a$ post a$d a$s%er
'!estio$s. The for!m is "he"ked o$ a reg!lar basis b )ria$ )is"hof to help a$s%er o!r
'!estio$s.
Three best-selling Crystal Reports boos, in their entirety#
$o%ens o" tutorials that &al you through each step o" buil!ing reports#
$o%ens o" e'pert tips learne! (on the )ob* that you can*t "in! any&here else#
+embers-only vi!eos#
+embers-only "orum#
,ccess to best-selling author, -rian -ischo"#
,s an a!!e! bonus, you get to re.uest speci"ic vi!eos that you personally &ant to see
online# This lets you customi%e the training "or your o&n nee!s#
Crystal Reports Online Training will help you to
break through the information overload by
presenting just what you need to know and do,
and how to do it.
Please aept my speial training invitation by
liking on the link below!
Clic /ere For 0our Special Invitation To Crystal Reports Online Training
Tha$k o! a$d talk to o! soo$#
)ria$ )is"hof
CrstalReportsO$li$eTrai$i$g."om

You might also like