Division by zero in crosstab formula
I have a crosstab with a formula field. The query returns something like
CategoryID Company MarketValue PaymentMode
1 ABC 1000 H
1 xyz 2000 H
3 efg 9800 H
Payment mode is half yearly indicated by 'H' I made a formula field to evaluate payment mode by
WhileReadingRecords;
number开发者_如何学编程Var mode;
if({PaymentMode}='H') then mode:=2 else mode:=12
Then I made another formula field
WhileReadingRecords;
numberVar mode;
numberVar result:={MarketValue}/mod;
result
However it returns division by zero error. Why is my formula for Payment Mode not evaluating properly. I tried placing the payment mode formula in report head and cross tab is 2nd header but it still throws the same error.
Two problems.
First syntax error - or rather typo here, last 'e' is missing :)
numberVar result:={MarketValue}/mode;
Second - you need to evaluate formuals in specified order. Say your first formula has name 'calc_mode', then second one should start with next statement:
EvaluateAfter({@calc_mode});
I'm glad you already found Arvo's answer, but I have a few suggestions to simplify your code:
Mode is a buit-in Crystal function (see Crystal's help files). So when I saw you using that word as the name for a custom variable, my brain did a backflip. How about calling it "numPayPeriods" instead?
Since your sample formula includes field values, Crystal implements WhileReadingRecords by default (again, see Crystal's help files). So adding it is redundant in this case. You can take that out entirely.
There's no need for 2 separate formulae in your example. Also, your Result variable is unnecessary in Crystal syntax. You can simplify the whole thing to just 1 formula:
if({PaymentMode}='H') then
{MarketValue}/2
else
{MarketValue}/12;
精彩评论