(edited to clean up)
I have an SSRS report with a multi-value parameter. What I need is for each value of the parameter to correspond to a condition in the "where" clause.
So my query is like this:
select stuff,...
WHERE
column A != column B OR
column C != column D OR...
just like that all the way down. It's to give results only if there's a difference between different pairs of columns.
So hope I'm describing it well. So, for example, if the above is my where clause, I want the parameter to have values like this:
"Difference between A & B"
"Difference between C & D"
and be able to select multiple...so only the ones the user selects are incorporated.
EDIT - PARTIAL SOLUTION **********************************************
Ok I have the logic, thanks to the right direction from Hannover Fist, I came up with this:
WHERE
col 1 <> CASE WHEN CHARINDEX("Where1",#Parameter) = 0 THEN col 1 ELSE col 2 END OR
col 3 <> CASE WHEN CHARINDEX("Where2",#Parameter) = 0 THEN col 3 ELSE col 4 END
...etc.....
This way, if the parameter is not selected, that part of the where clause looks for results where that column is not equal to itself--so none, of course...
However, one problem remains. This works in SSRS if I only choose 1 of the parameter values, but if I choose more than one, I get an error "charindex function requires 2 to 3 arguments." >-(
I deployed it and it spat something slightly different:
Argument data type nvarchar is invalid for argument 3 of charindex function
Something about SSRS's handling of this is flapdoodle, but I'm not sure what.
I'm a little fuzzy as to how you're trying to do this.
How about having your WHERE clause in your SQL and use your parameter to determine whether that part of the WHERE is used? This may not be exactly what you need but should give you an idea of what I mean.
WHERE (ColA <> ColB or CHARINDEX("Where1", #Parameter) = 0)
Your Parameter would have Where1 as one of the selections (for the Value - the Label could be more descriptive). If it's chosen, the CHARINDEX result would not be 0 and the ColA <> ColB condition would need to be true to show that record.
Repeat for each parameter/WHERE combo you need.
Got it.
As edited above, this code works (helpful nudge in this direction from Hannover Fist):
WHERE
col 1 <> CASE WHEN CHARINDEX("Where1",#Parameter) = 0 THEN col 1 ELSE col 2 END OR
col 3 <> CASE WHEN CHARINDEX("Where2",#Paremeter) = 0 THEN col 3 ELSE col 4 END
etc...
And the parameter issue is new to my experience, but put simply (which is not done often--hence my difficulty :-P), SSRS includes the commas between parameter values (which makes sense since we can use an IN statement such as
WHERE column IN (#Parameter)
So that is why it complained when I selected more than one. Incorporating the excellent selected answer here:
Passing multiple values for a single parameter in Reporting Services
Solved the rest of the problem :)
When you are passing the multivalue parameter to dataset
join the multivalue parameter with expression
= JOIN(Parameters!multivalue parameter.Value,",")
Related
I am trying to distinct count all values in the Incident_ID column where a number of IIF statements are met. The SSTS expression is running but the result is far from correct. When using SQL on SSMS, I am getting totally different results which makes me feel my expression is incorrect. I am also looking at the data and the data backs-up my expression isn't right.
Kindly see below. Many thanks.
=CountDistinct(IIF(Fields!Last_month.Value = 1
AND Fields!Clinic_group.Value = "AAA"
AND Fields!Incident_approval_Flag.Value = 1
AND (Fields!Incident_severity_code.Value <> "BBB"
AND NOT ISNOTHING(Fields!Incident_severity_code.Value))
,Fields!Incident_ID.Value, Nothing)
)
I am trying to generate a select statement with the hardcoded field in one column but with different values. Is there a better way to do this instead of writing another select statetment since there are different hardcoded values?
select
ppp.category_id,
ppp.city_id,
<<hardcoded values>>,
ppp.address,
ppp.status
from product ppp
where ppp.owner_id = 4186
Expressions in the select-list must be fixed at the time the query is prepared. You can't change that dynamically after the query has been parsed.
If your expression is a constant value, you can inject it as a parameter. Then you can pass the parameter to a prepared statement as you execute the query.
select
ppp.category_id,
ppp.city_id,
? as the_third_column,
ppp.address,
ppp.status
from product ppp
where ppp.owner_id = 4186
If you have a fixed list of expressions, you could use a CASE statement, and this means it can vary by row, or else by a query parameter:
select
ppp.category_id,
ppp.city_id,
CASE ppp.fetch_style
WHEN 1 THEN LOWER(ppp.mycolumn)
WHEN 2 THEN UPPER(ppp.mycolumn)
WHEN 3 THEN REVERSE(ppp.mycolumn)
ELSE ppp.mycolumn
END AS mycolumn,
ppp.address,
ppp.status
from product ppp
where ppp.owner_id = 4186
new to SSRS
I have table with column 1 is Department, and column 2 is The calculation
For example sum of the cost...
I have used the expression below to sum the cost
but I want to exclude the department that are null, but its no joy..
=Sum(IIF(Fields!ReturnOrder.Value = "1" + IsNothing(Fields!Department.Value) = 1, Fields!Cost.Value, 0))
column 1 is still showing the null department. I do not wish to show this...
I just want to have a column 1 showing the department names, that does not show the null rows.. and column 2 sum of cost where return value = 1
please help
To make your expression work the way you have it, you need to change the plus to an AND for logical operations and leave the ISNOTHING as a Boolean (without the = 1):
=Sum(IIF(Fields!ReturnOrder.Value = "1" AND NOT(IsNothing(Fields!Department.Value)), Fields!Cost.Value, 0))
I'm not sure what the ReturnOrder is for but left your condition in.
The expression you are looking for is
=Sum(IIF(Fields!ReturnOrder.Value = "1" AND IsNothing(Fields!Department.Value) = False, Fields!Cost.Value, 0))
Tip: In case your value is decimal instead of 0 use Cdec(0) to avoid errors.
To avoid displaying null departments I would suggest filtering your SQL query.
You can also do it by filtering the tablix
Expression: IsNothing(Fields!Department.Value)
Type: Boolean
Operator: Equal =
Value: False
Doing so will hide Null departments and your expression can be simplified to
=Sum(IIF(Fields!ReturnOrder.Value = "1", Fields!cost.Value, 0))
The best way is to alter your query:
SELECT *
FROM [YourTable]
WHERE [Department] IS NOT NULL;
You can also select the details row, click the Properties tab, and enter a formula in the "Hidden" property
=IIF(IsNothing(Fields!Department.value), True, False)
This says, "if department is null, hide this row, otherwise show it". The first method is better because less data is returned to your report. The second method requires that all rows are returned, and the report has to sort through which ones to show.
Select the detail row (click the three lines), select the Properties tab, and replace "False" with that formula:
I have this source data :
First I want to group by "Name" (I already did this part), after this I want to create the"category" column, if a "Name" group have any row type1 = A, then the Category is "X" else category = "Z"
This is the result I want:
How can I get the category group-column in reporting services?
My defacto method for this would be to edit the SQL query feeding the report and add the logic to add the group there. I assume that's not possible or you don't have access to the SQL layer, so here a way to do it completely in SSRS:
Insert another column to the right within your Name group
For the field expression, do a lookupset on the name field value and check if A exists in the results
=IIF(Array.IndexOf(Lookupset(Fields!Name.Value, Fields!Name.Value, Fields!Type1.Value, "DatasetName"), A) > -1, "X", "Z")
If you build the expression piece-meal, use the following expression to first check that your lookupset is working:
=JOIN(LookupSet(...), ",")
Then add the IIF(Array.IndexOf(...,A) > -1, X, Z) to see if the returned array contains your "A" value.
I'm creating a debtor invoicing report which has two parameters.
Parameter 1: This is a single value parameter called #booking_date. I filter the results(main dataset) by adding this into the query as a query parameter.
Eg. WHERE BookingDate = #booking_Date
Parameter 2: This parameter has two specified values - Yes or No. The parameter is called #live_run and the default value is 'No'. Basically, when this parameter has the default value of 'No', it does not limit/effect the results in any way. On the other hand, when this parameter has a value of 'Yes', it should limit the results by only displaying the bookings where the invoice has been paid off. There is a field I can use for this called Booking_Paid_off as follows - WHERE Booking_Paid_Off = 1.
I have parameter 1 in place, but I am unsure how to bring in Parameter 2 because it will be based on two conditions, do I need to use an If statement or a case statement? Do I need to create a new dataset for the second Parameter? I only want to limit the results with Parameter 2 ONLY if Parameter 2 has a value of Yes, otherwise I want the results to stay the same.
You have many options. You can switch out the Dataset entirely based on the parameter or use an IF inside the dataset to determine which query to run or simply check the parameter in your WHERE clause.
I recommend the latter.
SELECT
Field1,
Field2
FROM
Table1
WHERE
(
(#live_run = 'Yes' and Booking_Paid_Off = 1)
or (#live_run <> 'Yes')
)