开发者

When total weights are zero, display weighted average as zero instead of undefined

开发者 https://www.devze.com 2023-03-27 03:34 出处:网络
I am attempting to take the weighted average of a field, lets call it \"X\", which works fine so long as the field lets call it \"Y\" that the weighted average is with is not 0. However, when Y is 0 t

I am attempting to take the weighted average of a field, lets call it "X", which works fine so long as the field lets call it "Y" that the weighted average is with is not 0. However, when Y is 0 then the value for X does not appear in the report as it shouldn't, since it is an undefined value.

What I would like to do is have it so that if Y is 0, then X will be = to 0 and display 0 in the report.

I've have tried several things to get this to work, however they have not succeded. Currently what I am trying to do is set up a Display String Formating Formula to try and get it so that if Y is 0 then X is 0 and display this, however this requires a string to be the end result.

stringvar s;
NumberVar x := Weighted Average ( fieldX)
numbervar y := fieldY
if Y = 0 then x = 0;
X;

So my question is how do I convert a numberVar in开发者_JS百科to a stringVar, or is there a better method to go about doing what I am hoping to accomplish?


It doesn't seem to me that you need to involve stringvars at all here. There are some syntax errors in that code. If you put the formula you have written with the following small changes it should display fine in the report

numbervar x := weightedaverage(...);
numbervar y := {fieldY};
if y = 0 then x:= 0;
x

However, an even easier way would be to forego using variables at all

if {fieldY} = 0 then 0 else weightedaverage(...)
0

精彩评论

暂无评论...
验证码 换一张
取 消