Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Char and Int in Formula field Post Reply Post New Topic
Author Message
venky_115
Groupie
Groupie
Avatar

Joined: 15 Jun 2010
Location: United States
Online Status: Offline
Posts: 67
Quote venky_115 Replybullet Topic: Char and Int in Formula field
    Posted: 27 Sep 2011 at 1:42am
Hello All,
 
I want to divide two amounts in a formulae, for eg: amt1/amt2 but if amt2 is 0 then i should show "N/A" else should show the result.
 
in detail: amt1=100 and amt2=50 then the result should 2
               amt1=50 and amt2=100 then the result should 0.5
               amt1=100 and amt2=0  then the result should "N/A" .. etc
 
Back ground color highlighting also there, depends on the values greater than 7 and less than -7. if i convert this to totext then the hightlighting option is not working.
 
Can anybody suggest me the syntax for this formulae?
 
Thanks in advance


Edited by venky_115 - 27 Sep 2011 at 1:51am
Regards
IP IP Logged
jorrebor
Newbie
Newbie


Joined: 12 Sep 2011
Location: Netherlands
Online Status: Offline
Posts: 18
Quote jorrebor Replybullet Posted: 27 Sep 2011 at 2:36am
didn't try it out but something like

if amt2 = 0 then "NA" else result = amt1 / amt2

hope it helps

on the second issue: you can always convert back to to int with the conversion operators
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Sep 2011 at 3:41am
you will have to convert your result to a string as you have to have a consistent output data type for the formula. Since you want 'n/a' as one output you have to convert the numebr to a string also
 
if table.amount2=0 then 'N/A' else totext((table.amount1 / table.amount2))
IP IP Logged
venky_115
Groupie
Groupie
Avatar

Joined: 15 Jun 2010
Location: United States
Online Status: Offline
Posts: 67
Quote venky_115 Replybullet Posted: 27 Sep 2011 at 3:49am
yes dblank, i tried this previously but the background color logic is not working as this is string so not able to compare in the back ground formula
Regards
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Sep 2011 at 3:55am
what "background formula"?
Are you trying to summarize a summary?
IP IP Logged
venky_115
Groupie
Groupie
Avatar

Joined: 15 Jun 2010
Location: United States
Online Status: Offline
Posts: 67
Quote venky_115 Replybullet Posted: 27 Sep 2011 at 4:31am
no like if the result is >7 background color should yellow else if >-7 then diff color like this, hope you got this
Regards
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Sep 2011 at 4:49am
you can still do that just not using the value in the formula.
 
if (
if table.amount2=0 then 0 else (table.amount1 / table.amount2)
   ) >7 then cryellow else crothercolor.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Sep 2011 at 4:54am
or you can just do one calculation
if table.amount2=0 then 0 else (table.amount1 / table.amount2)
and then place this on repot canvas,
right click on it
select Common tab
find the "display string" and open the fomrula editor next to it
add in your formula here
if currentfieldvalue = 0 then 'N/A' else totext(currentfieldvalue)
IP IP Logged
venky_115
Groupie
Groupie
Avatar

Joined: 15 Jun 2010
Location: United States
Online Status: Offline
Posts: 67
Quote venky_115 Replybullet Posted: 28 Sep 2011 at 9:47pm

ok, thanks for all your replies

Regards
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.