How to create list as a parameter in SSRS? - sql

I have a report in 2005 SSRS which I want to add a parameter to. The parameter would be comprised of a group of zip codes, but be selected as a single item in the list.
For example, I would like to have 5 zip codes as one selection in the list and 3 for another, etc:
Select 11111,22222,33333,44444,55555,66666 AS Boondock
Select 77777,88888,99999 AS Timbuck
Select Zip Codes NOT IN (11111-99999) AS Everything Else
So my selections in the dropdown would be:
Boondock
Timbuck
Everything Else
Can anyone help me with how I should go about creating this parameter?

Create a simple string parameter to present to the user. Let's call it ZipCodeSet.
Create a dataset that examines the #ZipCodeSet parameter and returns the appropriate list of zip codes. Call it ZipCodeSelection.
Create an internal multivaue parameter that uses ZipCodeSelection as both its Available Values and Default Values. Call it SelectedZipCodes.
Use SelectedZipCodes in your report's datasets.

The easiest solution here would probably to use a Calculated Field on your dataset, called LocationDescription, for example:
=SWITCH(Fields!ZipCode >= 11111 and Fields!ZipCode <= 66666, "Boondock", Fields!ZipCode >= 77777 and Fields!ZipCode <= 99999, "Timbuck",True, "Everywhere Else")
The lone true statement at the end is due to the SWITCH expression reading left-to-right and exiting once it evaluates one of the switches as TRUE. This way for each of the items in your table of ZipCodes you will always end up with a TRUE result.
I assume you're evaluating a range of ZipCodes, and not exact values of 11111,22222, and so on? If so, the switch will have more values. A sample of your data would help if you want an exact answer.
Once you have built your Calculated Field, you can then set up a Parameter (called #LocationParameter) with available values based on a query of your LocationDescription field, then just filter your dataset using:
Expression:
= Fields!LocationDescription
Operator: =
Value:
#LocationParameter
(if you want multiple selections on your parameter, change the operator to IN)
Hope that helps.

Related

How to write SSRS expression with OR condition involving a field and a parameter?

I have a set of tablix results that im trying to filter based on OR condition but im having difficulty combining the two into one custom expression. [IsSafetyObservation] is just a boolean field and [Department] needs to be part of the multi-selected parameter values of [#Department]. Here's a screenshot of what it looks like as two separate filters but this is doing AND condition. When I tried to write custom expression I'm not using the write syntax because I get a red line when I try to reference the #Department parameter
tablix filter screenshot
custom expression attempt
You'll need to combine your expressions into one as you tried but instead of using IN, you should use InStr. InStr searches for a string inside another string and returns the position or 0 if not found.
First you would need to combine your parameters into a string using JOIN.
JOIN(Parameters!Department.Value, ",")
This will combine your parameters into a single string that you can now search for the Department field in the Department parameter.
InStr(JOIN(Parameters!Department.Value, ","), Fields!Department.Value) > 0
Also, SSRS doesn't always work well with Booleans (ugh) - so an expression of = (1 = 1) may work in some places for a Boolean result but not others so it's best to specify:
=IIF(InStr(JOIN(Parameters!Department.Value, ","), Fields!Department.Value) > 0
OR Fields!IsSafetyObservation.Value = False,
True,
False)

PowerQuery - Using a cell in a table as part of the code in a query (dynamically or not)

I am trying to use a cell as a parameter in Excel powerquery. The query works without this, but I have to manually input the values, which I need to constantly change them in the query in other to get the results that I want.
Query (Advanced Editor):
let
Criteria01 = Excel.CurrentWorkbook(){[Name="Servers"]}[Content][ServerSearch]{0},
Criteria02 = Excel.CurrentWorkbook(){[Name="Servers"]}[Content][ServerSearch]{1},
Criteria03 = Excel.CurrentWorkbook(){[Name="Servers"]}[Content][ServerSearch]{2},
Source = Sql.Database("SERVERNAMEHERE", "DATABASENAMEHERE", [Query="SELECT DISTINCT [...........] AND (TABLEPREF.COLUMNHERE like '%MANUALVALUE01%' OR#(lf)TABLEPREF.COLUMNHERE like '%MANUALVALUE02%' OR#(lf)TABLEPREF.COLUMNHERE like '%MANUALVALUE03%' OR#(lf)TABLEPREF.COLUMNHERE like Criteria01)#(lf)#(lf)#(lf)order by 1 asc"])
in
Source
"Servers" is the table name and "ServerSearch" is the column header. If I check the step for Criteria01/etc it will show me the correct value of that table that I need to use.
Original query done in Sql-Server. I have no problems when running the query with only LIKE '%MANUALVALUES%' lines.
My main goal is to automatically get N values of "MANUALVALUES" from a table in a sheet, which will be used as an input for comparing WHERE TABLEPREF.COLUMNHERE like '%VALUEHERE%'. I must use this and I can't get the whole table/database because there are way too many results besides the ones that I want.
However for test purposes at this moment, I am trying to use only 1-3 values, the first 3 of this table (Criteria{0}{1}{2} in the query above). However, if I try to do something like TABLEPREF.COLUMNHERE like Criteria01 I get the following error:
DataSource.Error: Microsoft SQL: Invalid column name 'Criteria01'.
Details:
DataSourceKind=SQL
DataSourcePath=dalsql390;itdw
Message=Invalid column name 'Criteria01'.
Number=207
Class=16
So my questions are:
I am getting the table cell value by the right way? Meaning:
Excel.CurrentWorkbook(){[Name="Servers"]}[Content][ServerSearch]{0}.
How do I refer this value in my query? Since the way that I wrote
that query bought me that error.
Also please note that if change TABLEPREF.COLUMNHERE like
Criteria01 to CHG1.CI_Name like "Criteria01" I get the
following error:
Expression.SyntaxError: Token Comma expected.
After fixed 1 and 2, how can I use this dynamically? For
example, instead of getting values of index 1 2 3, what if I want to
use a whole table? I know that using
Excel.CurrentWorkbook(){[Name="Servers"]}[Content] will bring me the whole table of values (1 column, unknown number of rows), but
how do I use this table content 1 by 1 in my query?
That will get the value, but you can't refer to steps inside of text values by putting the step name inside of it.
You have a couple options for doing this dynamically.
Use Value.NativeQuery to create a parameterized query where you can pass in other values as parameters. For example, Value.NativeQuery(Sql.Database("SERVERNAMEHERE", "DATABASENAMEHERE"), "select #a, #b", [a = 1, b = "x"]) will return the table [1, x]. You can put in the step name in the record value to pass that it (e.g. replace "x" with Criteria01).
Add the text values directly in the query field, e.g. [Query = "select " & Criteria01 ";"]. This is highly discouraged since this can lead to SQL injection issues.
For the third question, it depends what you want to do with the list of values. At some point you will likely need List.Accumulate to turn them all into a single text value which can be placed in the query value, and maybe to turn them into a record to place into the parameters value.

SSRS - How to add a default value to a parameter with Available Values from a query?

I have an SSRS report which contains a parameter ID, which will display sales totals for a person with selected ID. I get the options for the parameter by selecting "Get values from a query" under the Parameter's "Available Values" setting. However, in addition to these values, I want the first (default) value in the dropdown to be "All", which will display results for everyone combined. How can I add this hard-coded default to the dropdown list?
There are two ways to go about this.
I think the better way is to use a Multi-Value parameter and letting SSRS do the actual work. You would just need to change where you use the parameter to use it as a multi-value parameter (change = #PARAMETER to IN (#PARAMETER)).
For the Default values, use the same value field as was used for the Available Values.
The other way is to do it manually by appending an extra row to the parameter's dataset for the < ALL>. First you need to UNION an < ALL> to the data.
SELECT '<ALL>' AS EMPLOYEE_ID
UNION
SELECT EMPLOYEE_ID
FROM EMPLOYEES
For the Default value, Specify the value <ALL>.
Then you change you query or expression to use the EMPLOYEE ID or ALL:
SQL:
WHERE (EMPLOYEE_ID = #EMPLOYEE_ID or #EMPLOYEE_ID = '<ALL>')
SSRS Expression:
=IIF(FIELDS!EMPLOYEE_ID.VALUE = Parameters!EMPLOYEE_ID.Value OR Parameters!EMPLOYEE_ID.Value = "<ALL>", 1, 0)
Value: 1

Expression Criteria for Access

I've created a database with about 15000 records and I want to create a form that filters the records according to entries inputed in textboxes through a Query. For the most of my columns i've used this Expression :
Like "*" & [Forms]![Testform]![Testtxt] & "*"
I use "Like" so that if the user decides not to input anything in a textbox, the query ignores that parameter. However when it comes to Dates (I have two columns that contain Dates) I can't make it ignore the empty textbox when the user decides not to write anything. Can you help me make the expression below show all the records in the query if the DateTesttxt is empty ?
> [Forms]![TestForm]![DateTesttxt]
If you're using query designer, just add another condition
Is Null
so visually in query builder it will be something like:
Criteria: > [Forms]![TestForm]![DateTesttxt]
or: Is Null
UPDATE:
This should work as well as a single expression:
Is Null Or > [Forms]![TestForm]![DateTesttxt]
and it is more correct solution in case if you have conditions on more than one column

Replace null with zero in crosstab query in Telerik

I just created 2 cross table using wizard function of Telerik Standalone report designer tool
since ISCED 5 has values for private and public its showing properly
using same query I created second cross tab and
but since ISCED 6 table doesnt have values for "public" section its showing like this
how to show as zero for public section 2nd cross tab (when no values for specific row)
You should modify the value of the field using an expression to evaluate your condition.
Select the textbox containing the data corresponding to the column you like to format when the value is null.
In the property pan on the right select "Value"
Write in there your expression, it should be something like this:
=Iif(Fields.MyField IS Null,"0",Fields.MyField)
You should also consider if the value instead of null is empty and eventually cover this case in the expression if applicable.
= Iif(Fields.MyField IS Null OR Fields.MyField = "", "0", Fields.MyField)
More information on conditional formatting can be found here.
Let us know if this works for you.