Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: conditionally format a formula Post Reply Post New Topic
Author Message
STCPD
Newbie
Newbie
Avatar

Joined: 08 Jun 2012
Online Status: Offline
Posts: 18
Quote STCPD Replybullet Topic: conditionally format a formula
     Posted: 13 Jun 2012 at 7:19am
I'm trying to format a formula in format editor(font, color). I've tried:
IF {@%D1-HOMICIDE}> "0%" THEN CRRED
ELSE IF {@%D1-HOMICIDE}< "0%" THEN CRGREEN
ELSE
CRBLACK
 
But it is not working.
Here is the formula {@%D1-HOMICIDE} used:
IF {#D1-LAST HOMICIDE}= 0 THEN "N/C" ELSE IF {#D1-LAST HOMICIDE}<> 0 THEN
({#D1-HOMICIDE}-{#D1-LAST HOMICIDE})/{#D1-LAST HOMICIDE}*100 & "%"
 
I have yet to see less than 0 turn green and N/C always turns red. Basically I want all positive numbers to be red and all negative numbers to be green and everything else (N/C and 0%) to be black.
 
Thanks for your help!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Jun 2012 at 7:41am
create a numeric version of your display and use htat for your coloring
//numeric_percent
iF {#D1-LAST HOMICIDE}= 0 THEN 0 else
({#D1-HOMICIDE}-{#D1-LAST HOMICIDE})%{#D1-LAST HOMICIDE}
 
if @numeric_percent=0 then crblack else
if @numeric_percent>0 then crred else
if @numeric_percent<0 then crgreen else crblack
IP IP Logged
STCPD
Newbie
Newbie
Avatar

Joined: 08 Jun 2012
Online Status: Offline
Posts: 18
Quote STCPD Replybullet Posted: 13 Jun 2012 at 9:15am

Thanks that worked but I need to have the N/C in there if 

{#D1-LAST HOMICIDE}= 0
I tried
iF {#D1-LAST HOMICIDE}= 0 THEN "N/C" else
({#D1-HOMICIDE}-{#D1-LAST HOMICIDE})%{#D1-LAST HOMICIDE}
But I get an error string is required.
 
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Jun 2012 at 9:20am
THe formula was not for display but to return a numeric value so you can use the <,= and > options for color coding. You can still use your original fomrula for siplay and referenc this new fomrula only for coloring.
Make sense?


Edited by DBlank - 13 Jun 2012 at 9:20am
IP IP Logged
STCPD
Newbie
Newbie
Avatar

Joined: 08 Jun 2012
Online Status: Offline
Posts: 18
Quote STCPD Replybullet Posted: 13 Jun 2012 at 9:58am
I ended up using:
 
if {#D1-LAST HOMICIDE}=0 then crblack else
if (({#D1-HOMICIDE}-{#D1-LAST HOMICIDE})%{#D1-LAST HOMICIDE})>0 then crred else
if (({#D1-HOMICIDE}-{#D1-LAST HOMICIDE})%{#D1-LAST HOMICIDE})<0 then crlime else
crblack
 
And it seems to be working!
Thanks so much for your help!
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