Correct syntax for SSRS Nested IIf needed - service

I have the following expression. Can somebody tell me why it is printing 0.
=IIF(Parameters!StartMonth.Value <= 1 And Parameters!EndMonth.Value >= 1, ReportItems!txtTotal1.Value,
IIF(Parameters!StartMonth.Value <= 2 And Parameters!EndMonth.Value >= 2, ReportItems!txtTotal2.Value,
IIF(Parameters!StartMonth.Value <= 3 And Parameters!EndMonth.Value >= 3, ReportItems!txtTotal3.Value, 0)))
Thanks

It looks to me like if Parameters!StartMonth.Value is > 3, your statement will return 0.

Related

Drools rule with not condition with multiple condition causing error

When i use below condition with 'not' I am getting an error.
not(Obj1(value == 0) && Obj2(value <= 3))
However if i replace above condition as below I am not getting any casting exception
Obj1(value != 0) or Obj2(value > 3)
The rule looks like this:
rule "test_6"
salience 10
when
not(Obj1(value == 0) && Obj2(value <= 3))
then
.....
end
And this is the error I'm getting:
throwing error Error Message: org.drools.core.rule.GroupElement cannot be cast to org.drools.core.rule.Pattern
The && and || operators can only be used inside a single pattern. For example: Obj1( value > 3 && value < 10 || value == 0). According to the documentation, to separate Patterns, you have to use the and and or operators.
So, in your case, your rule should be:
rule "test_6"
salience 10
when
not(Obj1(value == 0) and Obj2(value <= 3))
then
.....
end
Note that it was not failing when you were using or because that was the right operator to use instead of ||.
Hope it helps,

Increment variable for if statement

Is there a more elegant way to write this? I dont want to use a for loop
if i==1 || i==6 || i==11 || i==16 || i==21 || i==26 || i==31 || i==36
function
end
basically i is the index of a vector, after each fifth element of this vector (starting with the first ) a specific function is applied. i starts with 1 and it increments after the if statement and just if it equals these values of the if condition the if statement is valid
EDITTED FOR MATLAB CODE OF MODULO
output = mod(input, 5); //this will output 1 if it is 1, 5, 11, 16
//input is your 1, 5, 11, 16 etc
//output is the result of modulo. else it is 0, 2, 3, 4
if(output == 1)
[previous answer]
i forgot how to write this in matlab but with your values, put it this way.
if(number%5==1)
any input 1 or 6 or 11 or any else that can add 5 to it, you'll end up in 1. else it will return false

Creating a for-loop that stores values in a new variable

I'm quite new to Matlab so excuse me for the basic question.
I need to make a for-loop that repeats it's self 384 times.
So :
for i=1:384
I now need the for loop to check if 2 certain variables have the value 1 through 10, and then let them store this in a new variable with that value.
So:
if x==1
somevariable = 1
elseif x== 2
saomevariable = 2
..
..
..
elseif y = 1
someothervariable = 1
etc etc.
Is there a way to write this more efficient?
Thank you!
The first think you can do is:
if(x >= 1 && x <= 10)
somevariable=x;
end
if(y >= 1 && y <= 10)
someohtervariable=y;
end
If you could post more information about "x" and "y", perhaps your script can be further "improved".
Hope this helps.

How can I determine the quarter for a given month in DataStage Transformer stage?

I want to produce a label for a data record, listing the Year and Quarter, e.g., 2014-Q2.
In SQL I can accomplish this task with something like the following:
SELECT VARCHAR(YEAR_) CONCAT '-Q' CONCAT(CAST(CEILING(CAST(MONTH_) AS
DECIMAL(4, 2)) / 3) AS CHAR(1))) AS QTR_ FROM TABLE
I am attempting to gather the same result in a transformer stage in DataStage (v 8.5), I thought the following crude derivation would work:
If
(Link.MONTH_ =< 3)
Then (Link.YEAR_ : '-Q1')
Else
(If
(Link.MONTH_ > 3 and Link.MONTH_ =< 6)
Then (Link.YEAR_ : '-Q2')
Else
(If
(Link.MONTH_ > 6 and Link.MONTH_ =< 9)
Then (Link.YEAR_ : '-Q3')
Else
('Y' : DSLink2.YEAR : '-Q4')
)
)
Perhaps a transformer stage is not the best option, all suggestions welcome because right now the derivation kicks an error.
The following derivation performs sufficiently:
If (DataSet.MONTH < 4) Then DataSet.YEAR:"-Q1" Else If (DataSet.MONTH > 3 AND DataSet.MONTH < 7) Then DataSet.YEAR:"-Q2" Else If (DataSet.MONTH > 6 AND DataSet.MONTH < 10) Then DataSet.YEAR:"-Q3" Else DataSet.YEAR:"-Q4"
To produce:
2014-Q1
2014-Q2
etc...
Take the month number, subtract 1, and determine the modulus when divided by three, then add 1.
Mod(DataSet.MONTH - 1, 3) + 1

Why doesn't this coffee-script print out?

So when the index is 0, I want to print it out:
a = [ 1, 2, 3 ]
for i of a
if i == 0
console.log a[i]
But there is no output.
i == 0 is never true...
i returns the index as a string, if you parse them as an integer, it would work
a = [ 1, 2, 3 ]
for i of a
if parseInt(i) == 0
console.log a[i]
It's because i will only be 1, 2 or 3, as you loop over the items in a, not the index numbers.
This works the way you described above:
a = [ 1, 2, 3 ]
for i in [0..a.length]
if i == 0
console.log a[i]
You shouldn't use of to loop over an array, you should use in. From the fine manual:
Comprehensions can also be used to iterate over the keys and values in an object. Use of to signal comprehension over the properties of an object instead of the values in an array.
yearsOld = max: 10, ida: 9, tim: 11
ages = for child, age of yearsOld
"#{child} is #{age}"
So you're trying to iterate over the properties of an array object, not its indexes.
You should use one of these for your loop:
for e, i in a
if(i == 0)
console.log(a[i])
for e, i in a
console.log(e) if(i == 0)
console.log(e) for e, i in a when i == 0
#...
Or, since you have an array and a numeric index, why not just skip the loop and get right to the point:
console.log(a[0])