SSRS 2008: iif IsNan statement Error wrong number of arguments - reporting-services

when I run the SSRS report with the following expression below, I get an error that says: wrong number of arguments. I get this error at the ).IsNaN, part of my statement. I don't see what i'm missing. Can anyone please help?
=iif(
(
(
(Sum(Fields!UNITS.Value, "SFY2011_SW_T19") / Sum(Fields!DISTINCT_CLIENT_PAY.Value, "SFY2011_SW_T19"))
- (Sum(Fields!UNITS.Value, "SFY2010_SW_T19") / Sum(Fields!DISTINCT_CLIENT_PAY.Value, "SFY2010_SW_T19"))
)
/ (Sum(Fields!UNITS.Value, "SFY2010_SW_T19") / Sum(Fields!DISTINCT_CLIENT_PAY.Value, "SFY2010_SW_T19"))
).IsNaN,
0.00,
(
(
(Sum(Fields!UNITS.Value, "SFY2011_SW_T19") / Sum(Fields!DISTINCT_CLIENT_PAY.Value, "SFY2011_SW_T19"))
- (Sum(Fields!UNITS.Value, "SFY2010_SW_T19") / Sum(Fields!DISTINCT_CLIENT_PAY.Value, "SFY2010_SW_T19"))
)
/ (Sum(Fields!UNITS.Value, "SFY2010_SW_T19") / Sum(Fields!DISTINCT_CLIENT_PAY.Value, "SFY2010_SW_T19"))
)
)

The particular error is probably because you should do IsNaN(Value) instead of Value.IsNaN but just in case you're trying to use Iif() to prevent a divide by zero error, I'll give you a bonus tip.
Doing this...
=Iif(CouldBeZero = 0, 0, SomeValue / CouldBeZero)
...will always throw an error when CouldBeZero = 0 because the division is evaluated first and the result passed to the Iif() function.
Instead do this...
=Iif(CouldBeZero = 0, 0, SomeValue / Iif(CouldBeZero = 0, 1, CouldBeZero))
...to ensure the division works and zero is displayed.

Instead of having that big complex value before .IsNAN, just use Single.IsNAN

Related

Is there a ROUNDDOWN() function in sql as there is in EXCEL

Say I have a table which has two columns i.e. Quantity and Percentages where my percentages are in decimals. Now I want to multiply these two columns and Round the value down to 2 decimals. Rounding down here means that all the numbers from 1-9 are rounded down. Is there an inbuilt function in SQL to do so as there is in Excel?
Examples:
13.567 should round to 13.56
136.7834 should round to 136.78
0.7699 should round to 0.76
I have tried searching for such a function online but couldn't come across an appropriate solution.
There's a FLOOR function, which can be adapted to your use case:
SELECT FLOOR(value * 100) / 100 AS RoundedValue
You can use TRUNCATE () for this rounddown
select TRUNCATE(2.847, 2) as rounddown
or
SELECT Floor(135.675); //for integer rounding, like 135
You can also use
select round(123.456, 2, 1) as rounddown
The 3rd parameter being non-zero will cause a truncation after the number of decimal points specified in the 2nd parameter.
DB Fiddle
https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/sqlref/src/tpc/db2z_bif_truncate.html
https://www.w3schools.com/sql/func_sqlserver_floor.asp
The solution to the problem is to truncate the extra decimal which can be achieved by using the extra parameter of the ROUND function which is ROUND(number, decimal_places, 0/1). Here if the last parameter is anything other than 0, it will truncate the rather than rounding off which is equivalent to the ROUNDDOWN() function of excel that I was looking for.
Alternatively, you can use the TRUNCATE() function, passing the number of decimal places to keep as the second parameter, which will drop off any extra decimals, acting as a ROUNDDOWN() function.
I hope this rounding utility helps somebody:
CREATE FUNCTION `get_round`(val DOUBLE, nDigits INT, RoundStyle VARCHAR(255)) RETURNS double
NO SQL
BEGIN
DECLARE a DOUBLE DEFAULT 0;
SET nDigits = ifnull(nDigits, 0);
CASE
WHEN UCASE(RoundStyle) IN ('ROUND NEAREST','', 'NEAREST', '', 'RND','ROUND', 'DEFAULT','DFLT', null) THEN #normal rounding, but up from 10.50#
SET a = round(val, nDigits);
WHEN UCASE(RoundStyle) IN('ROUND UP', 'UP') THEN #ROUND 10.554 to 10.56
SET a = ceil(val * (power(10, nDigits) )) / (power(10, nDigits));
WHEN UCASE(RoundStyle) IN('ROUND DOWN', 'DOWN') THEN #ROUND 10.555 to 10.55
SET a = truncate(val, nDigits) ;
WHEN UCASE(RoundStyle) IN('ROUND BANKER', 'BANKER','BANKERS ROUNDING') THEN #ROUND TO THE NEAREST EVEN 10.555 is 10.56 and 10.565 is 10.56
SET a = IF(ABS(val - TRUNCATE(val, nDigits)) * POWER(10, nDigits + 1) = 5
AND NOT CONVERT(TRUNCATE(ABS(val) * POWER(10, nDigits), 0), UNSIGNED) % 2 = 1,
TRUNCATE(val, nDigits), ROUND(val, nDigits));
WHEN UCASE(RoundStyle) IN('ROUND UP INTEGER', 'INT UP','UP INT') THEN #10.4 rounds to 11.0
SET a = ceiling(val);
WHEN UCASE(RoundStyle) IN('ROUND DOWN INTEGER', 'INT DOWN','DOWN INT') THEN #10.6 rounds to 10.0
SET a = floor(val);
END CASE;
RETURN ifnull(a, 0);
END
yes there are some Function in sql for round
ex:
SELECT ProductName, Price, FlOOR(Price) AS RoundedPrice
FROM Products;

Formatting result of multiply operation that getting from two columns in mysql

Problem 1
SELECT
f.MANHOUR_TOTAL,
f.MATERIAL_TOTAL,
e.NILAI_RATE * f.MANHOUR_TOTAL AS LABOUR_TOTAL
Which is the existing data is e.NILAI_RATE = 4.00 and MANHOUR_TOTAL = 11.00. The result is 44.0000.
How to keep two digits behind comma on LABOUR_TOTAL as 44.00
Problem 2, I want to use those LABOUR_TOTAL to next operation like this :
SELECT
f.MANHOUR_TOTAL,
f.MATERIAL_TOTAL,
e.NILAI_RATE * f.MANHOUR_TOTAL AS LABOUR_TOTAL
LABOUR_TOTAL + f.MATERIAL_TOTAL AS FINISHING_TOTAL
But it gives me null value on FINISHING_TOTAL. Is it possible to do like this ? Any help and suggestions is so appreciated.
For Problem 1 you want ROUND:
SELECT ROUND(e.NILAI_RATE * f.MANHOUR_TOTAL, 2) AS LABOUR_TOTAL
should do it!
For Problem 2, consider this:
SELECT
f.MANHOUR_TOTAL,
f.MATERIAL_TOTAL,
ROUND(e.NILAI_RATE * f.MANHOUR_TOTAL, 2) AS LABOUR_TOTAL,
ROUND((e.NILAI_RATE * f.MANHOUR_TOTAL) + f.MATERIAL_TOTAL, 2) AS FINISHING_TOTAL

Mask integer field in mysql

I need to mask integer field in mysql such that 9999911111 becomes 9900001111. I want to keep first 2 digits and last 4 digits and need to mark rest of the digits as 0 for the integers stored in the field.
I have created a query and it's working but I am not sure whether this is right way to do for integers or not.
update table_name
set field_name=CONCAT(SUBSTR(field_name, 1, 2),
REPEAT('0', CHAR_LENGTH(field_name) - 6),
SUBSTR(field_name, CHAR_LENGTH(field_name)-3, CHAR_LENGTH(field_name)));
Just trying a different approach .
SET #myVar = 344553543534;
SELECT #myVar - (SUBSTRING(#myVar, 4, LENGTH(#myVar) - 7) * 10000) ;
Above mentioned formula will give 344000003534 as the result. Tried with different combination and found it working.
So your query need to change as given below
UPDATE table_name
SET field_name=
(field_name - (SUBSTRING(field_name, 4, LENGTH(field_name) - 7) * 10000));
Explanation :
Consider Number, a = 344553543534;
Expected Result, b = 344000003534;
c = (a - b) = 344553543534 - 344000003534 = 553540000;
Now if you consider the result, c, 55354 is the numbers where masking required, and 0000 indicates the last 4 number to be left open.
So to get masked value, we can use the formula, b = a - c;
So now to get c, used SUBSTRING(a, 4, LENGTH(a) - 7) * 10000
EDIT : To keep only first two numbers, use 3 instead of 4 and 6 instead of 7. I assumed that you needed to keep first 3.
SET #myVar = 344553543534;
SELECT #myVar - (SUBSTRING(#myVar, 3, LENGTH(#myVar) - 6) * 10000) ;

Inequality constrained convex optimization in Matlab

I want to solve the following problem:
minimize E[T]
subject to λi * pi - μi <= 0; for all i, i=1,...,n
(λ0 + sum(λi*(1-pi))) - μ0 <=0;
pi-1 <=0; for all i, i=1,...,n
pi => 0; for all i, i=1,...,n
where E(T) = (λ0 + sum(λi*(1-pi)) / ( ( λ0 + sum(λi) ) * μ0 -(λ0 + sum(λi*(1-pi) ) )) + sum((pi * λi) / ((λ0 + sum(λi)) * (μi - pi * λi)) )
where all sum goes from 1 to n
That's what we know about the parameters: n = 2, λ0 = 0, μ0 = 1, λ1 = free parameter, λ2 = 2, μ1 = μ2 = 2,
This problem can be handled as an inequality constrained minimization
problem.
I know that λ1 goes from 0 to 3 and what i want to get are p1 and p2. p1 and p2 are between 0 and 1.
And how can i choose the starting points? Or is this problem can be solved in Matlab?
I tried to to use fmincon with interior point algorithm in Matlab. But i don't really know how a linearly increasing parameter can be in nonlinear constraints.
If you can tell me suggestions or other functions that can handle this problem properly i would be pleased.

How do I replace NULL with zero in an SSIS expression?

I have two columns ActivityCount and ParentValue. I created an expression:
ROUND((ActivityCount / ParentValue) / 100,16) * 100
But the problem is it returns NULL for some columns and I wanted to replace NULL with 0. I can't seem to find the answers.
Expression:
ISNULL(ParentValue) || (ParentValue == 0) ? 0 : ROUND(ISNULL(ActivityCount) ? 0 : ActivityCount / ParentValue / 100,16) * 100
For readability:
ISNULL(ParentValue) || (ParentValue == 0)
? 0
: ROUND((ISNULL(ActivityCount)
? 0
: ActivityCount / ParentValue) / 100
, 16) * 100
What it does:
If ParentValue field is NULL or has Zero, you do not have to perform a calculation because you will encounter Divide by Zero error. So, simply exit the expression by returning 0.
If ActivityCount field is NULL, replace it with zero before performing the calculation.
Recommendation:
I would recommend using COALESCE on the source query to replace the NULL values with zeroes and the calculation, if possible.
Test with ISNULL (SSIS, not the SQL expression), use the conditional operator
ISNULL(ROUND((ActivityCount / ParentValue) / 100,16) * 100) ? 0 : ROUND((ActivityCount / ParentValue) / 100,16) * 100
Try like below... it will help you...
ISNULL(ROUND((ActivityCount / ParentValue) / 100,16) * 100) || (ROUND((ActivityCount / ParentValue) / 100,16) * 100)= "" ? 0 : ROUND((ActivityCount / ParentValue) / 100,16
I would have said:
ISNULL(ActivityCount) || ISNULL(ParentValue) ? 0 : ROUND((ActivityCount/ParentValue)/100,16)*100
That way you are testing the simplest cases that will cause a NULL result rather than calculating the end case multiple times in your conditional.
(That being said, any of these will technically work.)