Division durch Null in Kreuztabellen- Formel
-
13-10-2019 - |
Frage
habe ich ein Kreuztabellen- mit einem Formelfeld. Die Abfrage gibt so etwas wie
CategoryID Company MarketValue PaymentMode
1 ABC 1000 H
1 xyz 2000 H
3 efg 9800 H
Zahlungsmodus Hälfte wird jährlich von ‚H‘ angezeigt Ich habe ein Formelfeld Zahlungsmodus durch
zu bewertenWhileReadingRecords;
numberVar mode;
if({PaymentMode}='H') then mode:=2 else mode:=12
Dann habe ich eine andere Formelfeld
WhileReadingRecords;
numberVar mode;
numberVar result:={MarketValue}/mod;
result
Allerdings gibt es eine Division durch Null-Fehler. Warum ist die Formel für Zahlungsmodus nicht richtig zu bewerten. Ich habe versucht, den Zahlungsmodus Formel in Bericht Kopf platzieren und Kreuztabelle ist die 2. Kopf aber es wirft immer noch den gleichen Fehler.
Lösung
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});
Andere Tipps
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;