Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: conditional formatting Post Reply Post New Topic
Author Message
ricky969
Groupie
Groupie
Avatar

Joined: 03 Jul 2008
Location: United States
Online Status: Offline
Posts: 53
Quote ricky969 Replybullet Topic: conditional formatting
     Posted: 30 Jul 2009 at 4:54pm
Is it possible to format a number on the following condition:
 
if {rawname} = 'Alfa' then {amount} without decimals
else with decimals
 
rawname    amount
alfa                      1
gamma           1.00
beta             12.76
 
sql database is passing numeric(15,2).
 
rawname is a string
amount is a number
 
i tried several formulas and nothing worked as expected. i'd like to handle that using (Format Field > Tab: Number > Customize.. > Decimals and click on the formula button)
 
i used a similar method to control the font, ie
 
if {rawname} = 'alfa' then crBold
else crRed;
 
and this worked.
 
thanks so much in advanced.
IP IP Logged
ricky969
Groupie
Groupie
Avatar

Joined: 03 Jul 2008
Location: United States
Online Status: Offline
Posts: 53
Quote ricky969 Replybullet Posted: 30 Jul 2009 at 5:02pm
i've just figured it out...
 
If {rawname} = "Alfa" then {amount}-4
else DefaultAttribute;
 
hopefully this will help someone else...i spent a couple of hours on it! Angry
IP IP Logged
ricky969
Groupie
Groupie
Avatar

Joined: 03 Jul 2008
Location: United States
Online Status: Offline
Posts: 53
Quote ricky969 Replybullet Posted: 31 Jul 2009 at 11:49am
ok so the formula is working only if i have a single condition!
The following formula does NOT work. it returns..."Bad formula result"
 
If {rowname} = "Alfa" or {rowname} = "Beta"
Then
      {amount}-4
Else
     DefaultAttribute;
 
anyone knows what's wrong? thanks.
 
Rick
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 31 Jul 2009 at 12:52pm

Sorry but I have not really tracked what you are doing with the amount-4.

If you want to set the number of decimal places conditionally based on the rowname where "alfa" shows no decimals and "gamma" and "beta" show 2 decimals then use this formula in the conditional format option for decimal places...
If {table.rawname} = "Alfa" then 0 else 2


Edited by DBlank - 31 Jul 2009 at 1:29pm
IP IP Logged
ricky969
Groupie
Groupie
Avatar

Joined: 03 Jul 2008
Location: United States
Online Status: Offline
Posts: 53
Quote ricky969 Replybullet Posted: 31 Jul 2009 at 1:43pm
Thanks...that works perfectly with the "...or..." condition too.
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 31 Jul 2009 at 1:50pm
FYI for that OR statment you can also use in statement...
If {table.rawname} in ["Alfa","Beta"] then 0 else 2
IP IP Logged
ricky969
Groupie
Groupie
Avatar

Joined: 03 Jul 2008
Location: United States
Online Status: Offline
Posts: 53
Quote ricky969 Replybullet Posted: 31 Jul 2009 at 2:37pm
yeah...that looks much cleaner.
thanks again
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