SSRS SWITCH showing error rather than answer - reporting-services

I am trying to do a simple calculation for my data. When the Order value = 6, then subtract the values of order = 1 - 2 -3. It returns #error instead of the the answer. How can i make it work correctly?
= SWITCH(
Fields!Order.Value = 6,
Sum(IIF( Fields!Order.Value = 1 ,CDBL(Fields!Totals.Value),CDBL(0)))
- Sum(IIF( Fields!Ordering.Value = 2 ,CDBL(Fields!Totals.Value),CDBL(0)))
- Sum(IIF( Fields!Ordering.Value = 3 ,CDBL(Fields!Totals.Value),CDBL(0)))
,
1 = 1,Sum(Fields!Totals.Value)
)

Related

Is there a convienient way to call a function multiple times without a loop?

I am currently making some code to randomly generate a set of random dates and assigning them to a matrix. I wish to randomly generate N amount of dates (days and months) and display them in a Nx2 matrix. My code is as follows
function dates = dategen(N)
month = randi(12);
if ismember(month,[1 3 5 7 8 10 12])
day = randi(31);
dates = [day, month];
elseif ismember(month,[4 6 9 11])
day = randi(30);
dates = [day, month];
else
day = randi(28);
dates = [day, month];
end
end
For example if I called on the function, as
output = dategen(3)
I would expect 3 dates in a 2x3 matrix. However, I am unsure how to do this. I believe I need to include N into the function somewhere but I'm not sure where or how.
Any help is greatly appreciated.
You can do it using logical indexing as follows:
function dates = dategen(N)
months = randi(12, 1, N);
days = NaN(size(months)); % preallocate
ind = ismember(months, [1 3 5 7 8 10 12]);
days(ind) = randi(31, 1, sum(ind));
ind = ismember(months, [4 6 9 11]);
days(ind) = randi(30, 1, sum(ind));
ind = ismember(months, 2);
days(ind) = randi(28, 1, sum(ind));
dates = [months; days];
end

What's wrong with this mySQL query? (concat and cast)

The following mySQL query always returns 0 results. The problem began when I added the part that uses the concat and the cast functions. Can you see any syntax error in it?
SELECT p.seccio_id as seccio,
count(distinct r.usuari_upc) as usuaris,
sum(r.preu) as preu
FROM report r, persona p
WHERE r.usuari_upc = p.persona_id
and ((r.any = 2017 and r.mes = 1)
or (r.any > 2017 and r.any < 2018)
or (r.any = 2018 and r.mes = 1)
or (2017 != 2018
and ((r.any = 2017 and r.mes > 1)
or (r.any = 2018 and r.mes < 1))))
and (p.any_id = '2017-2018'
or p.any_id = '2016-2017')
/* The problem is here. */
and ((r.mes < 9
and p.any_id = CONCAT(CAST(r.any - 1 as varchar(4)),"-",CAST(r.any as varchar(4))))
or (r.mes >= 9 and p.any_id = CONCAT(CAST(r.any as varchar(4)),"-",CAST(r.any + 1 as varchar(4)))))
GROUP BY p.seccio_id
ORDER BY p.seccio_id
You can't cast straight from the numeric values to varchar(4) - if you change them all to char(4), you lose the syntax errors.

How to set correct zoomScaleSensitivity for svgpanzoom library?

I am using svgpanzoom library (link on github repository) in my project . I was setting some initial value:
var minValue = 0.8;
var maxValue = 6;
var numberOfSteps = 5;
instance.setMinZoom(minValue);
instance.setMaxZoom(maxValue);
After that i was trying calculate and set new value for zoomScaleSensitivity:
var newValueForZoomScale = (maxValue - minValue) / numberOfSteps;
instance.setZoomScaleSensitivity(newValueForZoomScale);
Unfortunately , in this case i have 6 or 7 zoom's steps (depends of screen resolution). My question is how i can set correct value for zoomScaleSensitivity and always have only 5 (numberOfSteps) zoom's steps?
Try
var newValueForZoomScale = (maxValue - minValue) / (numberOfSteps - 1);
That's because if you divide by N, you'll get N+1 steps like:
if start is 1
if end is 6
divide by 5 (number of steps you want) and get (6-1)/5 = 1 for step distance
you'll get 6 steps: 1, 2, 3, 4, 5, 6
So you have to divide by 4, then you'll get (6-1)/4 = 1.25 and 5 steps: 1, 2.25, 3.5, 4.75, 6

What does this recursive function mean?

I've been tasked with implementing a recursive function in MIPS. This function is
function1(n) = n-5 (if n <= 3)
otherwise = 4*function1(n-1) - n*function1(n-3)
One of the test cases is if n = 6, then the result is 200.
How do you get 200 from entering 6 in this function? To me it looks like the answer should be 2. Is there something I am not understanding about recursion, or am I understanding the function wrong? I am so confused
You seem to be misunderstanding the function somewhere. Here are the steps I followed to arrive at 200:
function1(6) = 4*function1(5) - 6*function1(3) (by rule 2)
function1(5) = 4*function1(4) - 5*function1(2) (by rule 2)
function1(4) = 4*function1(3) - 4*function1(1) (by rule 2)
function1(3) = 3-5 = -2 (by rule 1)
function1(2) = 2-5 = -3 (by rule 1)
function1(1) = 1-5 = -4 (by rule 1)
Substituting back...
function1(4) = 4*-2 - 4*-4 = -8 - -16 = 8
function1(5) = 4*8 - 5*-3 = 32 - -15 = 47
function1(6) = 4*47 - 6*-2 = 188 - -12 = 200

Available Filters With Specified Ranges In SSRS

I am working on a Chart in my report.
As I have too many records where CountId = 1, I have set up a filter showing an available values list like this:
CountId :
1
2
3
Between 4 to 6
Between 7 to 9
Above 10
If I set the available value 1 or 2 or 3 it shows results, but I don`t know how to set a filter for between and above.
I want a filter some thing like this - available filters are:
1
2
3
4
Above 5 or greater than equal to 5
You've got a mix of operators, so maybe you should look at an expression based filter to try and handle these different cases, something like:
Expression (type Text):
=Switch(Parameters!Count.Value = "1" and Fields!Count.Value = 1, "Include"
, Parameters!Count.Value = "2" and Fields!Count.Value = 2, "Include"
, Parameters!Count.Value = "3" and Fields!Count.Value = 3, "Include"
, Parameters!Count.Value = "4 to 6" and Fields!Count.Value >= 4 and Fields!Count.Value <= 6, "Include"
, Parameters!Count.Value = "7 to 9" and Fields!Count.Value >= 7 and Fields!Count.Value <= 9, "Include"
, Parameters!Count.Value = "Above 10" and Fields!Count.Value >= 10, "Include"
, true, "Exclude")
Operator:
=
Value:
Include
This assumes a string parameter Count populated with the above values.
This works by calculating the parameter and field combinations to produce a constant, either Include or Exclude, then displaying all rows that return Include.
As mentioned in a comment, it's difficult to follow exactly what you're asking here. I've done my best but if you have more questions it would be best to update the question with some sample data and how you'd like this data displayed.