SSRS Report Builder - How do i nest an IIF stmt inside a COUNTDISTINCT(IIF( stmt? - reporting-services

I have two statements below. For any question other then the two listed in the second IIF statement, i want to show the % based on the COUNTDISTINT(IIF() statement. For the two questions listed, i want to return a "N/A" value.
=COUNTDISTINCT(IIF(Fields!Answer_Title.Value <> "No", Fields!UNIQUE_ANSWER.Value, NOTHING))/COUNTDISTINCT(Fields!EVAL_ID.Value)
=IIF(Fields!Form_Component_Title.Value = "One Guide Introduction" OR Fields!Form_Component_Title.Value = "Avoided jargon and acronyms Provider", "N/A", NOTHING)
I am a beginner in SSRS Report Builder, I have only used this for about 3 weeks now. I have tried things that a beginner would most likely try such as just combining the two statements with '+', but i need some advice to assist me with this expression.

Related

Is it possible to have a group by parameter in a SSRS Matrix report and have the columns rearranged depending on the group by chosen?

I haven't really worked with SSRS Matrix reports and I'm not sure if what I am trying to do is even possible.
The user can enter a begin and end year. They want the ability to group on either CBA, CRA or Client. The CBA and CRA choice would subtotal after each name, but the client would not. The columns to include would remain the same for each choice. However, they want whatever is grouped by to be moved to the front of the report. If you choose CBA, the columns relating to CBA should appear first. If you choose client, the columns relating to client should appear first.
Is any of this possible with a matrix report? If so, where do I start? Should any of this be done in the stored procedure or should it all be done in Visual Studio? I am using Visual Studio 2017. Below is a sample of what the output should look like.
Any help is greatly appreciated.
report sample
This is certainly possible. There are several ways to do this and you will have to choose how much of it is done in your dataset query/stored proc and how much is done via SSRS expressions.
There are a few things to think about no matter what route you decide on.
Your dataset query or stored proc must always return a dataset that has the same column names with the same datatypes and in the same order
Avoid hiding columns in the report designer as this does not work well
If the dataset returns lots of rows then you might want to do some of the work in the query
The SSRS Way:
If you wanted to do this entirely in the report designer, all the affected columns and groups would need to be set as expressions. For example, in a simplified version of your report, the second column expression would be something like.
=SWITCH(
Parameters!myParam.Value = "CBA", Fields!CBAName.Value,
Parameters!myParam.Value = "CRA", Fields!CRAName.Value,
Parameters!myParam.Value = "Client", Fields!ClientName.Value
)
The Columns header would also have to be a similar expression.
=SWITCH(
Parameters!myParam.Value = "CBA", "CBA Name",
Parameters!myParam.Value = "CRA", "CRA Name",
Parameters!myParam.Value = "Client", "Client Name"
)
The Row Group total (in grey on your example) would also have to be a similar expression.
You would have to repeat this for all affected columns.
Next
You would also need to change the RowGroups in a similar fashion. So you would add a row group and then the "Group On" and "Sort By" expressions to the same thing.
=SWITCH(
Parameters!myParam.Value = "CBA", Fields!CBAName.Value,
Parameters!myParam.Value = "CRA", Fields!CRAName.Value,
Parameters!myParam.Value = "Client", Fields!ClientName.Value
)
It's quite a long winded process but it's not actually that bad to do.
The SQL Method
The idea is basically the same, based on the parameter we pass in, we swap out the columns in the results but we alias them so they look the same in the SSRS dataset. We also have to provide the text for the column headers in the results so we don't have to work it out in the report designer.
Here's a very simple example.
SELECT
CASE #myParam
WHEN 'CBA' THEN CBAName
WHEN 'CRA' THEN CRAName
WHEN 'Client' THEN ClientName
END AS ColumnAValue
CASE #myParam
WHEN 'CBA' THEN 'CBA Name'
WHEN 'CRA' THEN 'CRA Name '
WHEN 'Client' THEN 'Client Name'
END AS ColumnACaption
, *
FROM myTable
Here we are swapping out the content of ColumnAValue and ColumnACaption. In the report designer, we would display ColumnAValue and set the Column Header expression to
=FIRST(Fields!ColumnAHeader.Value)
The Row Groups would both simply sort by ColumnAValue
This method means a lot less work in the report designer.
There are other options but these two methods I what I usually go for as they are the simplest. The SQL method is easier for other developers to understand because there is not much 'hidden' such at the row groups sorting and grouping properties.
At the end of the day it's down to you to decide what you feel comfortable with but hopefully this gives you enough to start.

SSRS if Statement with two lines in the false condition

I'm converting crystal reports over to SSRS and need to put the equivalent of this if statement in an expression.
if({RPT_ReceiptStatusHeader.receipt_id_type} = "Trailer ID") then
BarcodeC128B({RPT_ReceiptStatusHeader.trailer_id})
else
BarcodeC128B({RPT_ReceiptStatusHeader.receipt_id_type})
BarcodeC128B({RPT_ReceiptStatusDetails.item})
Here is what I've come up with but this is incorrect.
=IIf(RPT_ReceiptStatusHeader.receipt_id_type = "Trailer ID", StringToBarcode({RPT_ReceiptStatusHeader.trailer_id}), StringToBarcode({RPT_ReceiptStatusHeader.receipt_id_type}), BarcodeC128B({RPT_ReceiptStatusDetails.item})
The syntax for an SSRS if else is for example....
=IIF(Fields!LineTotal.Value > 100, True, False)
But how can I put multiple statements in the false condition?
Are you trying to create 2 barcodes with this? With barcodes, I'm assuming that you would want them separated vertically (so that they are one above the other, since putting them next to each other would make accurate scanning very problematic). If this is the case, then I would try something along the lines of:
=IIf(RPT_ReceiptStatusHeader.receipt_id_type = "Trailer ID",
StringToBarcode({RPT_ReceiptStatusHeader.trailer_id}),
StringToBarcode({RPT_ReceiptStatusHeader.receipt_id_type}) & chr(10) &
StringToBarcode({RPT_ReceiptStatusDetails.item})
What you will end up with is 2 barcodes oriented one above the other. You will have to handle font size and possibly even the height of the control.
BTW - I changed the "BarcodeC128B" to "StringToBarcode" in the second part of the "then" portion of your statement.
BTW2 - I'm feeling your pain with the CR to SSRS conversion. We're making the conversion ourselves and have most of the easy (scheduled and "on demand") work done, we just have a couple hundred application based reports to convert over.

SSRS Ignore Filters Based on a specific Filter used

Good day
I have a SSRS report that has 4 filters.
One of the 4 filters is a "Search Parameter".
When the user uses the "Search Parameter" (field/filter, types something in), I want to ignore the other three filters despite them having values or not.
I've tried CASE/SWITCH statements in the Expression of the Parameter (DataSet Properties), but no luck.
Does anyone have an idea on how I can get this done
The Filter is quick and convenient but only allows AND relationships between the filter criteria and you want an OR relationship here.
The good news is that you can make more complex filter logic by using expressions. We will create a boolean filter expression that evaluates to whether you want to filter the row or not and compare this to True.
Have only one filter criterion and click the expression editor button. Make the expression something like:
=IIF(IsNothing(Parameters!SearchParameter.Value), Fields!Field1.Value = Parameters!Field1Parameter AND Fields!Field2.Value = Parameters!Field2Parameter AND Fields!Field3.Value = Parameters!Field3Parameter, Fields!SearchField.Value LIKE "*" & Parameters!SearchParameter.Value & "*")
Make the expression type be Boolean, the Operator = and the Value True.

Adding Fields into an expression in an SSRS 2008 report

Thank you in advance for taking your time to answer my question.
I am having trouble with expressions in the SSRS reporting system.
The Field I am adding required fields from the dataset I provided in the report, however when I try to preview the report I get the Following message:
"A Value expression used for the report parameter ‘Policies_Total’
refers to a field. Fields cannot be used in report parameter
expressions."
This is my expression:
=IIF(Sum(Fields!policy_id.Value, "DataSet1") Is Null, 0, Count(Sum(Fields!policy_id.Value, "DataSet1")))
That was suppoed to be converted from Crystal reports which has the following expression:
If IsNull ({usp_rep_agent_cases;1.policy_id}) then
0
Else
Count ({usp_rep_agent_cases;1.policy_id})
Any help is much appreciated.
Thank you
I think it may be as simple as understand that a 'parameter' should be passed into SSRS before fields are created for the most part. If this parameter is DEPENDENT on the value of something else first being chosen you cannot list it first as the field is not yet populated to my knowledge. It appears you are trying to use an expression to count something from a field from a dataset when you just make a dataset and reference that field directly. So instead of trying an expression you may choose a few other options instead:
Choose on the left pane of your parameter 'Available Values' selected 'Get values from a query'. You may use your query which is a 'dataset', value is self explanatory, label is what the end user will see display.
The option 'Allow null' value will accept a null value
You may run into situations where multiple datasets may need to be used, multiple selects or querying objects. In my experience with SSRS it gets mad at times when you try to reference a dataset used to display data with a dataset used to determine an event or action. SSRS also gets relativity slower the more Expressions you do so doing a whole report with nothing but expressions versus taking the power of the built ins of the RDL language is not really worth it IMHO.
For SSRS expressions you need to use IsNothing for NULL checking, something like:
=IIF(
IsNothing(Sum(Fields!policy_id.Value, "DataSet1"))
, 0
, Count(Sum(Fields!policy_id.Value, "DataSet1"))
)
In fact the whole expression seems a bit odd; what are you specifically trying to achieve with your expression? Are you just trying to count non-null values?
=Sum(IIf(IsNothing(Fields!policy_id.Value), 1, 0), "DataSet1")
Also, your error seems to be saying that a parameter is referencing a field when this isn't allowed, which may not be solved by changing syntax; I think more information about what you're trying to achieve is required here.

SSRS Report - Dataset Filters

I've written a report for SSRS and Im using dataset filters with expressions to filter the report info. I seem to either have this expression wrong or the filter is not working correctly:
=IIf(Parameters!DoctorID.Value = "All" Or Parameters!DoctorID.Value = "", "*", Parameters!DoctorID.Value)
What I want to accomplish with the above code is if DoctorID = ALL or "" (blank) then I want to omit it from the filters so I return information for all doctors. However, whenever the value of DoctorID = ALL, I'm returning no rows what so ever. It should be the case that i'm getting ALL rows since DoctorID is not a specific number.
Does the "*" (star) not denote an omitting of that filter? Am I doing something wrong here?
Thanks!
The filter formula you provide is only half the equation: what is the operator and what are you comparing this to? And yes, I haven't seen SSRS use asterisk as a wildcard.
Consider putting your filter into the query for the dataset. The SQL WHERE clause can get pretty powerful. I would write your filter into the query as
...
WHERE
#DoctorID = 'All' OR #DoctorID = ''
OR #DoctorID = myTable.DoctorID
This will also let you move to a multiple value parameter pretty easily.