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;
numberVar 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;
Related
I'm using Visual Studio Code and have been typing code like this repeated times:
fmt.Println("Result of test 1:", test1Val/total)
fmt.Println("Result of test 2:", test2Val/total)
fmt.Println("Result of test 3:", test3Val/total)
fmt.Println("Result of test 4:", test4Val/total)
...
Seeing as the Numbers are in ascending order, is there a way to repeat a line of code while incrementing the numbers within? (a bit like dragging down a cell in Excel)
EDIT: I'm looking for the VScode function for repeated lines with different values, the code is just an example.
Codegeneration is not the answer to your problem.
A stucture similar to this is:
testResults := []int{1, 42, 666}
total := 777
for t, result := range testResults {
fmt.Printf("Result of test %v: %v\n", t, float64(result)/float64(total))
}
Regardless of code generation or arrays, if you still want to write your code or text like that and look for some way of insert incrementing or decrementing sequence of numbers, you can use the vs-code-input-sequence extension and multiple cursors to manipulate and configure the way the sequence is inserted.
Although it's not the best for code efficiency, it's still a very good tool for documentation and other text editing situations. It used the input panel (keyboard shortcut) to insert syntax like, the start, operator, step, digit and radix.
https://marketplace.visualstudio.com/items?itemName=tomoki1207.vscode-input-sequence
Extension credit is to tomoki1207
In the Running Total Fields, how do you set up a Distinct Count that includes blank values as one of your conditions?
Just found a solution. It's:
isnull({table.column})
Before asking, that's what I tried, but it wasn't working. So for people like me who tried that and it didn't work, that's because you have multiple conditions in your Running Total, and for whatever reason it only works when you edit your syntax and place that near the top of your conditions instead of the bottom. Don't know the reason, but it's working now.
I'd recommend replacing the field you're currently totaling with a new Formula. Something that doesn't ever come up blank, like:
If ISNULL {yourfieldhere} THEN "Blank" ELSE {yourfieldhere}
or if it's an empty string:
If {yourfieldhere}="" THEN "Blank" ELSE {yourfieldhere}
You can replace "Blank" with whatever suits you, even just an empty " " space or 0. But then it's at least something distinct to be counted.
I am trying to use the formula below to set conditions in LibreOffice but I keep getting an error. What am I doing wrong with the statement below:
=IF(G2<=2,'negative',IF(OR(G2>2 & G2<=3,'neutral',IF(OR(G2>=4,'positive))))))
Thanks
It seems, that in your formula is missing the last ':
'positive))))))
should be 'positive'))))))
Also the
&
is string-concatenation in LibreOffice, so you need here the equivalent to OR() and that is AND().
But you can simplify your formula to
=IF(G2<=2,'negative',IF(AND(G2>2,G2<=3),'neutral','positive'))
The first test is if the number is lower than 2 (negative),
the second test is if the number is between 2 and 3 (neutral)
and then there is no further test needed as it is the only remainig possiblity.
For a different locale, a slightly shorter, and I'd say simpler, version that also avoids the need for OR/AND:
=IF(G2<=2,"negative",IF(G2<=3,"neutral","positive"))
Once <=2 first test is handled (either but outputting negative or by proceeding to the 'result if FALSE') there is no longer the possibility of 2 or less, so the AND is not necessary.
The above though does fill a gap left by OP between 3 and 4.
I am running a series of experiments using behaviourspace and outputting my results in spreadsheet mode. My model runs at a temporal rate of 1 day per tick. Every 365 days a year variable increments. I would like to report the value of another variable to the spreadsheet at the end of each year.
Does anyone know how to accomplish this using the behaviourspace "Measure Runs using these reporters" box? It seems that I can either report the value at every tick or at the end of the model. Ideally I would like to report every x ticks.
I have attempted to put a conditional statement in the reporters box but behaviourspace throws an error. An alternative option would be to create a list as the model runs and export it at the end of each run - but this produces unwieldy output for analysis. Is this my only option or am I missing something?
Any advice much appreciated. Thanks
I don't think you can report occasionally. Instead, I would do the following:
In your code, define a function called yearly-report and always report a value.
to-report yearly-report
ifelse (ticks mod 365) = 0
[report your-calculation-here ]
[report ""; where "" is an empty placeholder text that you may ignore.]
end
Then in your behavior-space commands, call yearly-report
I've done a lot of googling and haven't been able to find a solution to my issue. I have a report that displays the number of calls for different help desk categories/sub categories. It has the category name and 4 other columns. When a child category is displayed it indents the whole line, but I want the last 4 columns to stay aligned under their respective labels. I'm using Crystal Reports 10 and don't see any where to enter a formula to conditionally position the fields for the last 4 columns. Even if I did see a place to enter a formula I'm not sure how I would determine where to place the fields because the X position for the field doesn't actually change when the line is indented. The only thing I could think of to handle this is to figure out how many tabs each line is indented and then subtract those from the X position, but I'm not sure how I could tell how far a line has been indented. Any suggestions would be greatly appreciated. Thank you
The SAP User Guide actually has quite a bit of information on this. You can set indentation values and you can do a lot of conditional formatting. Check the guide for CR 2011 out here and Section 11 is mostly about how to format reports. 11.3.10.9 talks about indentation, but I suggest you browse the whole section 11. And even though it's for CR 2011, it doesn't vary much for other versions.
Hope that helps,
Chris