SSRS Expression for Image - reporting-services

I have a requirement to display either of two images based on a condition. The expression I have used for the image is as below.
Image1 =IIF(Fields!Field1.Value= 269, "checked", "unchecked")
Image2 ==IIF(Fields!Field1.Value= 270, "checked", "unchecked")
The dataset returning the values for Field1 can return more than 1 rows but the above expression takess the value only from the 1st row that the dataset returns. How can I modify by expression so that it checks all the rows that my dataset returns i.e. is there any way to iterate through all the rows returned by the dataset and write an expression.

You can nest an IIF condition in an aggregate to check against all values in the scope:
=MIN(IIF(Fields!Field1.Value= 269, "checked", "unchecked"))
In this expression, either "checked" or "unchecked" is being returned for each Field1.Value. If one or more of those values is "checked", "checked" will be returned because "checked" is alphabetically less than "unchecked".
Other aggregate functions can be used with a nested IIF to check against all records in a scope, but this one seems to be the simplest for what you are trying to do here.

Related

SSRS Visibility Hide iif All

Just wondering if it is possible to do the following on SSRS for a textbox visibility (hide), it seems to return an error for me:
=iif(parameters!category.value = "All",True,False)
I have a long list of category so therefore is impossible to list them all, is it possible to the above? I keep getting an error with the above-outlined syntax
I assume the category parameter is multi-select with available values fed by a SQL query. You can use the Count property on the parameter to get the number of selected items and compare that to the number of items returned by the SQL query using the COUNT() SSRS aggregate function with a scope of the dataset. If the number of selected items matches the number of available values then they must be all selected.
So your code would look like:
=IIF(Parameters!category.Count = COUNT(Fields!CategoryName.Value, "CategoryParameterDataSetName"), True, False)
In this case the dataset that contains all of your available values is named CategoryParameterDataSetName and contains a field named CategoryName. Change these values as appropriate.

IIF Statement Not Returning a Value in SSRS

I'm very confused by this situation, i've written quite a few IIF statements and always get them to work. I have two columns in my dataset called CATEGORY and PCT, what i'm trying to do is return the PCT value for only one specific value in CATEGORY.
For example, I have the following table of data
Category PCT
A .50
B .75
I have placed a textbox on my report and have written the following expression to return the PCT value if Category = B, like so:
=IIF(Fields!Category.Value = "B", Fields!PCT.Value, " ")
For some reason this expression returns empty every single time. When I just put Fields!Category.Value in the textbox as a test then the value A returns which is as expected.
I'm really thrown-off by this and I know i'm missing something very simple - can someone help?
Its important that we understand the context of the textbox as the expression seems valid.
If you placed a single textbox on your report and used your above expression (with references to the datasets) ONLY the first row of your dataset will be evaluated. In which case the expression will always evaluate to the same result.
Can you confirm that the control you are using is indeed a textbox? If it is then i believe you do need a reference to the dataset and the expression will look more like this:
=iif(First(Fields!Category.Value, "datasetName") = "B", First(Fields!PCT.Value, "datasetName"), " ")
This would only evaluate the first row in your dataset.
If you were to do this in a tablix using your original expression then it should work.

Match field value of parameter from the same dataset using ssrs

I have a dataset FiscalYearMonth which contains
Fiscalmonthyear
Fiscalmonthkey
I have also Parameters!FiscalYearMonth.Value
How can I get Fiscalmonthkey for FiscalYearMonth parameter ? I tried the following expression but didn't work
=lookup(Fields!FiscalMonthYear.Value,Parameters!FiscalYearMonth.Value, Fields!FiscalMonthKey.Value, "FiscalYearMonth")
I think you have your function parameters in the wrong order, try this:
=lookup(Parameters!FiscalYearMonth.Value, Fields!FiscalMonthYear.Value, Fields!FiscalMonthKey.Value, "FiscalYearMonth")
This bascially says "in the dataset 'FiscalYearMonth', compare the value of Parameters!FiscalYearMonth.Value to the field Fields!FiscalMonthYear.Value for each row in the dataset and return the value of Fields!FiscalMonthKey.Value where there is a match".
Note that the Lookup() function only returns a single value and will stop at the first match found.

Show all records/some records based on parameter value

I have stored procedure which returns around 100 rows. One column is Category.
In SSRS, I've created DataSet related to that stored procedure. On Report body I have Tablix, which I relate to DataSet.
Now, I have additional parameter, called FilterColumn, which consist all different categories from dataset, plus one row called "All products".
How to filter tablix based on that parameter to show me whether products from specific categories or all products?
You need to set up a filter similar to the following:
Where the expression is:
=IIf(Parameters!FilterColumn.Value = Fields!Category.Value
or Parameters!FilterColumn.Value = "All products"
, "Include"
, "Exclude")
This matches the row Category based on the parameter value, or, if the value = All products, will include all rows.
As mentioned in the comments and the other answer, this is possible in the SP too, but since it seems to be specifically to demonstrate the functionality this should do the trick at the report level.
I have created some solution and worked for me:
In Expression field, I put first expression:
1. Iif(Parameters!FilterColumn.Value = "All", 1, Fields!Category.Value)
In Value field, I put second expression:
2. Iif(Parameters!FilterColumn.Value = "All", 1, Parameters!FilterColumn.Value)
So, when I choose "All" value in parameter, then first expression will result 1, and second expression will result 1, and i have 1 = 1 which is true for all rows, and I got all rows in table.
When I choose specific category from parameter, then in first expression result will be Fields!Category.Value and in second expression will be Parameters!FilterColumn.Value. Simple, I got Fields!Category.Value = Parameters!FilterColumn.Value, or just give me rows where category is that choosen in parameter.
Pass the Additional Parameter to your store procedure, so you send data that is already sorted to your report. This will avoid multiple Tablix created depending on your parameter selection.

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"