I am having a problem with a query that uses iif statements per the below:
Items to Exclude: IIf([Is this FAC]="No",[ID2],IIf(([Is this FAC]="Yes") And ([ID2]="CsaId"),"False",[ID2]))
The above 'Items to Exclude' field should populate ID2 where the 'Is this FAC' field is (1) No OR (2) is Yes AND ID2 is not 'CsaId'.
When the Query is run with the above formulas and as per the below it works fine, returning FALSE where it should in the 'Items to Exclude' field per the formula.
The problem is if I then enter <>"False" in the Criteria field per the below (as I want to then filter out any exclusions, i.e. False items)
it seems to turn the field into a parameter query and gives a window pop up per the below instead of just filtering out the FALSE statements.
I would appreciate any help/ideas.
Thanks
Unfortunately in WHERE and GROUP BY clauses you cannot use column aliases like you did. Replace all Is this FAC by formula for this column. So, in your case for Items to Exclude the formula will be
Items to Exclude: IIf(IIf([Id1]="FAC","Yes","No")="No",[ID2],
IIf((IIf([Id1]="FAC","Yes","No")="Yes") And ([ID2]="CsaId"),"False",[ID2]))
After this condition will work.You can think about simplifying this formula.
Also you can save your query without criteria and then use it as subquery for filtering out unnecessary records.
Related
I am in report builder and I have my primary dataset that is from a SQL database, I also then created a second dataset (enter data). I need to compare 2 fields from each dataset to retrieve the correct value from the 2nd dataset and populate a column on my report. I have tried the IIF statements and Lookup statements but I keep getting the error "report item expressions can only refer to fields within the current dataset".
I have a attached a screenshot of what I am trying to do....
The IIF statement I tried to use.. If Acctnum and prodid = each other return IncodeNumber
=IIF((Fields!AcctNum.Value=Fields!AcctNum.Value, "IncodeAccount") AND
(Fields!ProdId.Value =Fields!ProdId.Value, "IncodeAccount")),(Fields!IncodeNumber.Value, "IncodeAccount"),"True")
See code in my problem.
You need to use LOOKUP(). The problem with LOOKUP() is that is can only compare a single value from each dataset. However, we can easily get around this issue by concatenating the two values you need to compare.
Note: This assumes the expression will be in a tablix that is bound to your first dataset and that IncodeAccount is your second dataset - the values you want to lookup. If this is not the case just adjust the expression accordingly
So for you, you probably need to do something like this..
=LOOKUP(
Fields!AcctNum.Value & "||" & Fields!ProdId.Value,
Fields!AcctNum.Value & "||" & Fields!ProdId.Value,
Fields!IncodeNumber.Value,
"IncodeAccount"
)
I've used two pipe symbols to join the values to avoid incorrect matches being found. e.g. Account 123 and product ID 4567 would incorrectly match to Account 1234 and product ID 567 as they would both be 1234567 when joined. By using the || the match would be 123||4567 and 1234||567 respectively.
You may need to convert the values to string using CStr()
Alternative approach
If you are going to do this 'join' multiple times in the same dataset then you could add a calculated column to the dataset that concatenates the two columns. Then you can use this single field in the lookup which will make things a little simpler.
Or, you could do this concatenation in a database view which would make things even easier.
My current definitions for this report are like this:
DataSet A = a pretty extensive query with 'AND ai.Channel IN (#ChannelParameter)'
DataSet B = Channel 'Select distinct channel from Account_Info'
result set 'Retail Channel' or 'Wholesale'
Parameter = #ChannelParameter is set to Allow Multiple Values and is Getting the values from Query.
Tablix Properties - Filters
Expression [Channel]
Operator IN
Value =Parameters!ChannelParameter.Value(0)
When I run the report and select 'Retail Channel', I get the correct data.
When I run the report and select 'Wholesale', I get the correct data.
When I run the report and select both values, I get zero rows returned.
When I modify the query for DataSet A to be ai.Channel IN ('Retail Channel','Wholesale'), I get all of the rows. There are no rows in the data where the Channel field is NULL.
I've seen and tried some changes to the expression in the parameter using a JOIN statement, but no better results there.
What am I missing?
You filter expression is incorrect, as you stated (0) that means only the first parameter value will be used.
Having said that, it looks like you are already filtering the data in your A dataset so there is no need for the tablix filter, just remove it.
I'm trying to use a query (query2) based on another query (query1).
On a form where both are displayed, I use VBA to add filters for query1. This works for query1, but query2 keeps using the unfiltered query1 as its source no matter what I try. Any suggestions welcome
Many thanks
Two ways to approach this:
Approach 1: in Query2 set Filter on Load to 'Yes', then have your VBA add the filter clause to Query2 and re-run it. So, if you want to filter Query1 based on column [foo] having the value "bar", your VBA would add this to the Filter property of Query2:
Query1.[foo] = "bar"
Approach 2: Parameterize Query 1 - have it use a WHERE clause that points to a control on the form (perhaps a hidden text control if you don't want users to see it). The structure of your VBA would then:
1. change the value of the hidden control
2. Requery Query 1, which will now use the new parameter value
3. Requery Query 2, which will be based on the values of Query 1 (which points to the hidden control).
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.
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"