SQL Reporting Services IIf statement - reporting-services

I am working on a report that should execute a different equation depending on the status of the boolean field CLIPPING_FLAG. However, no matter the state of this field, the second equation seems to always be selected. Here is my expression.
=IIf(Fields!CLIPPING_FLAG.Value = False, (Fields!DRY_M2.Value/Fields!FLITCH_COUNT.Value),
(Fields!CLIP_M2.Value/Fields!BUNDLE_COUNT.Value))

Related

How To Show Or Hide A Tablix Based On A Bit Field In SQL Server Reporting Services

I have a multi row dataset that I want to do a lookup on and take the bit/Boolean value of one of it's columns and apply it to the hidden property of a tablix.
Here is the expression for the hidden property on the tablix.
= IIF(Lookup(6, Fields!ServiceOfferingID.Value, Fields!UseCustomCalculator.Value, "JobBuyerDetails") = 0, True, False)
If the ServiceOfferingID is 6, get what is in the UseCustomCalculator column to show or hide the tablix.
I don't know if you can compare values like this, what may need to be a string or if they are all just variants.
I have tried converting the values to string with CStr(), putting quotes around the searched value (6 in this case) but have had no luck getting the tablix to show or hide correctly.
There doesn't seem to be a good way to debug this, check what the Lookup is returning etc.
How can I change my expression to get it to work?
What am I missing?
I am pretty new to SQL Server Reporting Services.
I am using SQL Server 2008 R2.
Debugging in the traditional sense isn't really an option. What I normally do is add a textbox and set the expression to the expression you want to test, in your case, set the expression to
=Lookup(6, Fields!ServiceOfferingID.Value, Fields!UseCustomCalculator.Value, "JobBuyerDetails")
and see what you get.
Once you've established what is being returned and corrected the comparison then you can simplify the hidden expression a little.
The hidden expression would just be something like (assuming lookup issues are resolved)
=Lookup(6, Fields!ServiceOfferingID.Value, Fields!UseCustomCalculator.Value, "JobBuyerDetails") = 0
There's no need to use an IIF here as the comparison will return return or false anyway.

Error when trying to use Where clause in SSRS expression

This SO link, WHERE Caluse in SSRS expression, verifies that my syntax is correct yet I get this error:
"An error occurred during local report processing.
The definition of the report is invalid.
The Value expression for the text box 'txt1A_EMA' uses an aggregate expression without a scope. A scope is required for all aggregates used outside of a data region unless the report contains exactly one dataset."
My expression:
=Sum(IIF((Fields!COU_EMA.Value, "CA_Summary") = 1, (Fields!Amount.Value, "CA_Summary"), 0))
There are 3 Datasets in my report. The one I want is "CA_Summary" and the expression above was built with the expression builder.
The field, (Fields!COU_EMA.Value, "CA_Summary"), is a boolean (1 or 0) and I get error either with a 1 or a "true" (no quotes).
I probably could fix it if I knew what the definition of "scope" is. . . maybe.
The scope is where you want to look in order to get the values you're looking for. It could be a data set, group, etc. In your expression it appears CA_Summary is the scope.
I would try modifying the expression a bit. Since you say COU_EMA is bit field, maybe use TRUE. This is also assuming the matrix is using the data set CA_Summary.
=Sum(IIF(Fields!COU_EMA.Value = TRUE, Fields!Amount.Value, 0))
If your matrix isn't using that data set and it still doesn't work try
=Sum(IIF(Fields!COU_EMA.Value = TRUE, Fields!Amount.Value, 0),"CA_Summary")

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 IIF Filtering on Tablix

I am working with SSRS and have a tablix that needs certain rows excluded if a value in a multi-value parameter is not selected. For example, the multi-value parameter is 'Include Loss' and the values are 'Yes' and 'No'.
So if the user selects 'No', then I want the tablix to exclude rows where Description field is equal to the text "Loss Transaction".
I am trying to write an expression to filter on the tablix as follows, but having no luck.
=IIF(Parameters!IncludeLoss.Value="N", Fields!Description.Value, NOTHING)
and use '<>' for the 'Operator' and then:
="Loss Transaction"
I get the error 'Failed to evaluate the FilterValue of the Tablix'. Any suggestions? Thanks in advance!
Filters have an implicit AND relationship - that is, all the conditions have to be True for the filter to take effect.
Accordingly, you can have two filter conditions set:
=Parameters!IncludeLoss.Value is equal to N (add a second condition)
=Fields!Description.Value is equal to ="Loss Transaction"
Alternatively, for complex conditions (or conditions involving OR or Null which aren't supported in a standard filter) you can just use one condition and set that condition's expression to something more complex that evaluates to a boolean and test that against True. For example:
=Parameters!IncludeLoss.Value = "N" AND Fields!Description.Value = "Loss Transaction"

How to substitute NULL parameter for subreport?

I am using SSRS 2008 R2. My RDL has several subreports in it which all take one field value only from this parent RDL as their inputs. This one field value is called "people_id". There are some instances though where there are 0 records returned from the parent RDL. When this happens, I get the following error when I run this report from the parent RDL:
An error occurred during local report processing. Object reference not set to an instance of an object.
Even though I tried setting the paremeter value for my subreports to both:
people_id
and
=iif(isnothing(Fields!people_id.Value),"",Fields!people_id.Value)
How can I successfully avoid this error when there are no records?
I guess it's too late but in case of helping anyone else.
Some values in an expression can evaluate to null or undefined at report processing time. This can create run-time errors that result in #Error displaying in the text box instead of the evaluated expression. The IIF function is particularly sensitive to this behavior because, unlike an If-Then-Else statement, each part of the IIF statement is evaluated (including function calls) before being passed to the routine that tests for true or false. The statement =IIF(Fields!Sales.Value is NOTHING, 0, Fields!Sales.Value) generates #Error in the rendered report if Fields!Sales.Value is NOTHING.
From http://msdn.microsoft.com/en-us/library/ms157328.aspx
I had a similar issue and ened up with writing a custom function.
Instead of =iif(isnothing(Fields!people_id.Value),"",Fields!people_id.Value), can you try =iif(isnothing(Fields!people_id.Value),NOTHING,Fields!people_id.Value)?