For a dataset in SSRS reports, I've created a calculated field with below expression and it works fine.
=(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*Fields!Factor.Value
But sometime we can have factor value as 0. So, I modified above expression with below:
=iif(Fields!Factor.Value = 0,(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*1,(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*Fields!Factor.Value)
But this throws below exception:
The Value expression for the textrun ‘Textbox2.Paragraphs[0].TextRuns[0]’ uses an aggregate function on data of varying data types. Aggregate functions other than First, Last, Previous, Count, and CountDistinct can only aggregate data of a single data type.
Can someone please help to get resolve this issue?
This doesn't seem to be an issue with the IIF, but the datatypes seem to be mismatched. I have a few suggestions to try. First, you could try to multiply the true value by 1.0 as I assume the datatypes are decimal or double. The other option would be to use something like CInt to covert the value to the correct datatype. CInt would likely be inappropriate for decimals as it would round off any decimal values, but the idea is the same. Since your expression doesn't use any aggregates and only uses normal operators, it must relate to something other than the IIF.
Here's a useful link to break down the datatypes and conversion methods. Choose the most appropriate conversion and apply it to the 1.
EDIT: The expression should be the following.
=iif(Fields!Factor.Value = 0.00,
(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*CDbl(1),
(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*Fields!Factor.Value)
Related
I'm trying to select all of the lowest tier(in the "nest") possible values that are numbers, and not strings, in a nested json. This will include arrays and objects. Currently, im using this code
(?<=:)\s*([+-]?\d+(?:\.\d*(?:E-?\d+)?)?)\b\s*(?=(?:\{|,)\s*\"[^\"]*\":)
(which is mostly from this question)
and it works, if it isn't the last value of an object, or in a list. My main problem is, that it can be fooled. for example, if i have these two "a":":1,", ":":akey-value pairs next to eachother, it sees the number 1 as a value, except that the actual value is ":1,". How can i make a foolproof system for this?
Im excpecting it to not select anything, that couldn't be an integer or a float. I would like to keep the middle part of my original regex, beacuse it also needs to work with scientific notations.
Hi I am new here and want to solve this problem:
do k=1,31
Data H(1,k)/0/
End do
do l=1,21
Data H(l,1)/0.5*(l-1)/
End do
do m=31,41
Data H(17,m)/0/
End do
do n=17,21
Data H(n,41)/0.5*(n-17)/
End do
I get error for l and n saying that it is a syntax error in DATA statement. Anyone know how to solve this problem?
You have three problems here, and not just with the "l" and "n" loops.
The first problem is that the values in a data statement cannot be arbitrary expressions. In particular, they must be constants; 0.5*(l-1) is not a constant.
The second problem is that the bounds in the object lists must also be constant (expressions); l is not a constant expression.
For the first, it's also worth noting that * in a data value list has a special meaning, and it isn't the multiplication operator. * gives a repeat count, and a repeat count of 0.5 is not valid.
You can fix the second point quite simply, by using such constructions as
data H(1,1:31) /31*0./ ! Note the repeat count specifier
outside a loop, or using an implied loop
data (H(1,k),k=1,31) /31*0./
To do something for the "l" loop is more tedious
data H(1:21,1) /0., 0.5, 1., 1.5, ... /
and we have to be very careful about the number of values specified. This cannot be dynamic.
The third problem is that you cannot specify explicit initialization for an element more than once. Look at your first two loops: if this worked you'd be initializing H(1,1) twice. Even though the same value is given, this is still invalid.
Well, actually you have four problems. The fourth is related to the point about dynamic number of values. You probably don't want to be doing explicit initialization. Whilst it's possible to do what it looks like you want to do, just use assignment where these restrictions don't apply.
do l=1,21
H(l,1) = 0.5*(l-1)
End do
Yes, there are times when complicated explicit initialization is a desirable thing, but in this case, in what I assume is new code, keeping things simple is good. An "initialization" portion of your code which does the assignments is far more "modern".
I am creating a data quality framework for a database that looks at single cells of each data type and sees whether or not their values are acceptable.
For data type string:
I just use a regular expression to define what is valid
For other data types (Integer, Timestamp, Boolean, TimeDelta, Float, ... ):
I don't have any standard way of recording what is valid
Is there an equivalent to Regular Expressions for other data types? Like IntegerRegEx's?
For example, lets say I have a field that must contain numbers between 0 and 65535, or I have a field that can only contain odd numbers...
It would be nice if this IntegerRegEx was also a string (just like normal RegEx's), so I could store IntRegEx's and StringRegEx's in the same table.
Thanks in advance!
If you want something that's a string and regex-like, you could just use regexes. Just have a standard way of converting each type to a string, and write regexes against the string form. It might be awkward for some and error-prone for others, but it's simple and doesn't involve creating your own expression language or loading code straight from the db and evaling it.
I guess depending on what language you're programming in, say PHP, you could store a mathematical expression (a string), for example $x >= 0 && $x <= 65535 or $x % 2 == 1.
With regex, you would write something like this, right?
if (!preg_match($regexFromDb, $fieldValueFromDb)) {
// validation fails
}
So with mathematical expressions, you'd do the same thing, e.g.
$x = $fieldValueFromDb;
if (!eval("return $mathExprFromDb")) {
// validation fails
}
This is just exemplary code. Of course you should safeguard your code against the dangers of running arbitrary stored executable code, and also against gibberish expressions crashing your script.
I think this is as close as you're gonna get, because the "IntegerRegEx" you seek already has a name... Math. ;)
exception No_intersection of string
fun check_in ((m1:real, b1:real), (m2:real, b2:real)):real*real =
The function is supposed to check for an intersection between the two lines. Each pair argument is a slope and a y intercept. I am supposed to find the intersection between the two if it is exists.
I can't make to seem this work for some reason, and have been struggling with this for hours.
Reals are not an equality type in SML, so (m1-m2) = 0 is a type error.
The reason for this is that the limited precision of floating-point representations can give unexpected results due to rounding errors (e.g. (1.0/7.7)*7.7 = 1.0 would return false). You can get around this by using the == operator from the Real library, i.e. Real.==(m1-m2,0) (or just Real.==(m1,m2)). But keep in mind that it can be unreliable.
The second problem is that, according to the return type, your function is supposed to return a value, not print it. All you need to do here is state the return value in the else clause, i.e. just replace print((x,y)) with (x,y).
And for what it's worth, I'd avoid using exceptions if you can; they kind of go against the idea of functional programming. Try returning a (real*real) option instead.
In Informix, how can I cast a char(8) type into a money type, so that I can compare it to another money type?
Using "tblAid.amt::money as aid_amt" did not work.
Using "(tblAid.amt * 1) AS aid_amt" did not work.
try this -->
select (disb_amt::NUMERIC) disb_amt from tmp_kygrants;
You may be able to compare the amounts as numeric.
First question - why on earth are you not storing a numeric value in a numeric column? This would make the rest of your question moot. It would also mean that your system will perform better. When you need to store data values, use the obvious type; do not use a string type unless the data is a string.
As already noted, you can use the non-standard Informix cast notation:
SELECT some_column::MONEY FROM WhereEver;
You can also be more careful about the cast type - using MONEY(8,2) for example. You can also use the standard notation:
SELECT CAST(some_column AS MONEY(8,2)) FROM WhereEver;
This assumes you are using IDS 9.x or later -- older products do not support casts at all. However, in general, Informix is pretty good about doing conversions automatically (for example, converting numbers to strings). However, strings are compared lexicographically and not numerically, so a CAST is probably wiser in this context -- but avoiding the need for a cast by using the correct type in the first place is wiser still.
'tis been a while since I played around with informix and I don't have a running instance handy at the moment. However, there are two things that can cause a problem here:
1) since it is a char(8) it can contain values that can not be casted to numeric without a bit of 'cleanup'. E.g. "abc". Or "1,234,567.00".
2) Trailing spaces. (char as opposed to varchar).
What informix error do you get on your explicit cast (::money)?