How to display "All Selected" when parameter (Select All) is selected in SSRS? - ssrs-2008

Using SSRS 2008 r2...I have a report with a single-value parameter and three multi-value parameters, Class1, Name2 and Name3. I'm hoping for an explanation to one thing that I'm seeing and information on a second thing.
One, on the image, Class1 and Name2 both have the (Select All) parameter selected but Class1 is displaying the concatenated parameter variable list whereas Name2 is showing Null. Why is that? If anything, how can I get Class1 to be similar to Name2 and show Null?
But my desired wish is to have Class1, Name2 and Name3 display the text"All Selected" when the parameter (Select All) is chosen. How can this be achieved?
Thanks.

The datasets referred by Class1, Name2 and Name3 should contain the value All Selected.
To do that you need to add the below codes to the existing datasets:
UNION
SELECT 'ALL SELECTED' as DefaultValue
Then put the default value of all your required parameters to "All Selected".

If you're using a dataset as a source for your multi-select parameter:
"DataSet2" is my source for the multi-select parameter "pmPlant". I check if the number of selected items in your mutli-select parameter match the number of items in your source dataset. If it is, then display your desired text ("All Plants" in this case), if not then then use the "Join" function to combine the selections as a ";" separated list.
=iif(Parameters!pmPlant.Count = CountRows( "DataSet2", ),"All Plants", Join(Parameters!pmPlant.Label,"; "))

This should work:
=IIF(Parameters!ParameterName.Count = COUNT(1, "Dataset Name"), "All", Parameters!ParameterName)

Related

How to parameterize a column for aggregation in Power BI desktop?

I have users who would like to be able to modify what columns a table aggregates by. My issue is that I seem unable to do this in Power BI. I basically want to be able to do the following in SQL:
SELECT
<OrgLevel1>,
<OrgLevel2>,
SUM([Revenue])
FROM [Data]
GROUP BY
<OrgLevel1>,
<OrgLevel2>
;
where the user can change <OrgLevel1> and/or <OrgLevel2> to be any of { "(All)", [Department], [Product] }.
The issue may be related to this post: https://community.powerbi.com/t5/Desktop/Calculated-Column-Table-Change-Dynamically-According-to-Slicer/m-p/655991#M314800
Here's a link to a workbook that illustrates this issue, TestParameterizeGroupby.pbix (hosted by Google Drive). I've also included field definitions below with screenshots. Thanks for any help.
TestParameterizeGroupby.pbix
Link: TestParameterizeGroupby.pbix (hosted by Google Drive)
Problem
[Org Level 1] and [Org Level 2] fields are not recalculating from the users' selection. Only the default values are shown.
Expected result in table
"Org Level 1", "Org Level 2", "Revenue"
"(All)", "(All)", 28
Note
The purpose is to have parameterizable organization level fields so that the report user can aggregate by all, department, product, or both in either order.
Table and column definitions
'Data' = DATATABLE(
"Department",
STRING,
"Product",
STRING,
"Revenue",
DOUBLE,
{
{"DeptA", "ProdX", 5.0},
{"DeptA", "ProdY", 6.0},
{"DeptB", "ProdX", 10.0},
{"DeptB", "ProdY", 7.0}
}
)
'Data'[Org Level 1] = SWITCH(
'Org Level 1 Parameter'[Org Level 1 Parameter Value],
0,
"(All)",
1,
[Department],
2,
[Product]
)
// Problem: [Org Level 1] and [Org Level 2] fields are not recalculating from the users' selection. Only the default values are shown.
'Org Level 1' = DATATABLE(
"Org Level 1",
STRING,
"Org Level 1 Parameter",
INTEGER,
{
{"(0) (All)", 0},
{"(1) Department", 1},
{"(2) Product", 2}
}
)
'Org Level 1 Parameter'[Org Level 1 Parameter] = GENERATESERIES(0, 2, 1)
'Org Level 1 Parameter'[Org Level 1 Parameter Value] = SELECTEDVALUE('Org Level 1 Parameter'[Org Level 1 Parameter], 1)
Table 'Org Level 1' has a 1-1 relationship with 'Org Level 1 Parameter' on column [Org Level 1 Parameter].
The user selects the value for 'Data'[Org Level 1] by selecting the value for 'Org Level 1'[Org Level 1].
Tables and columns for [Org Level 2] are defined in the same way as [Org Level 1].
Screenshots
Report view:
Data view:
Model view:
Cross-reference to post in Power BI forum:
Power BI Forum: How to parameterize a column for aggregation
One solution to this is to add two list values parameters and use their values in Power Query M code to modify the database query. Lets assume that you have a table Data with columns Department, Product and Revenue. For simplicity I will add one more column, named Dummy Column, with all rows having the same value (e.g. null). I will explain why later in this post. So the table looks like this:
Then in your report specify a query when adding this table to your model (lets assume we will import it, but in general you can do this in DirectQuery too):
Now if you look the M code you will see the above query there:
Source = Sql.Database(".", "StackOverflow", [Query=" select ....
Now define couple of parameters, that the end-user can use to select how the data should be aggregated. Lets name them Level 1 and Level 2:
The value of a parameter can be used in M by parameter name, and & is used to concatenate strings. So if there is a parameter Name with value Samuel, the expression "Hello, " & Name & "!" will be evaluated as Hello, Samuel!. The idea is to check the value of our parameters and modify the database query accordingly.
In the select part, we will replace the name of the field selected, or we will put '' (empty string) in case of <All> (I surrounded parameter values with brackets to be more easily to distinguish parameter values from database field names). So the expression should look like:
"select " & (if #"Level 1" = "<Department>" then "Department" else ..." (and so on)
Because there is a space in our parameter's name, we need to surround it with #" and ", so Level1 can be referenced simply as Level1 in the code, but Level 1 becomes #"Level 1".
The group by part is a bit trickier. We should add a comma between field names, add or not field name, or even omit the group by at all (in case both parameters are set to <All>). To simplify this, I added one dummy column, with all rows having the same value (e.g. null) and always group by this column. This way building the group by clause is way more simpler - in case the parameter value is not <All>, we should add , fieldname. So the code could look like this:
"group by DummyColumn" & (if #"Level 1" = "<Department>" then ", Department" else ..." (and so on)
So the final M code is this:
let
Source = Sql.Database(".", "StackOverflow", [Query="select#(lf) " & (if #"Level 1" = "<Department>" then "Department" else if #"Level 1" = "<Product>" then "Product" else "''") & " as [Org Level 1]#(lf) , " & (if #"Level 2" = "<Department>" then "Department" else if #"Level 2" = "<Product>" then "Product" else "''") & " as [Org Level 2]#(lf) , SUM(Revenue) as Revenue#(lf)from Data#(lf)group by DummyColumn" & (if #"Level 1" = "<Department>" then ", Department" else if #"Level 1" = "<Product>" then ", Product" else "") & (if #"Level 2" = "<Department>" then ", Department" else if #"Level 2" = "<Product>" then ", Product" else "")])
in
Source
Now the end-user can change parameter values, by clicking Edit Queries -> Edit Parameters:
And select how to group the data:
By default, Power BI Desktop will warn you first time, when particular query is executed:
If you want to turn this off, go to File -> Options and settings -> Options -> (GLOBAL) Security and make sure Require user approval for new native database queries is not selected:
When the end-user changes parameter values, the data will change too, e.g.:
Or:
And so on...
This trick works well in Power BI Desktop when every user has its own copy of the .pbix file. However, if you publish it, first changing parameter values is not very convenient (you must go to datasat's settings) and more important, changing parameter values affects all users, which are looking at this report. You can also use it to modify Table.Group statements generated by Power Query Editor, in case you want to aggregate the data in Power BI, but changing the database query is easier and more flexible.
If you want to enable this scenario for concurrent multi-users scenarios for published reports, you can use slicers and What-if parameters. Unfortunately, What-if parameters can be numeric (you can't define the list of values there), so you can use measures to "decode" the int value of the parameter and write some DAX code to perform different aggregations accordingly. It is more work, but if it is needed, it can be made too.

Kentico getting data from multiple choice fields that use SQl causes GetValue to return a number instead of the actual name

I am hoping that there is just a method that I am missing.
Right now i am using {% CurrentDocument.GetValue("marketType").Replace("|", ", ") #%} which works totally fine if I have a list of options. As soon as I switched my field to get data by using :
SELECT 0 AS ItemID, '-Select-' marketType
UNION ALL
SELECT ItemID, marketType FROM BBUS_MarketType
{% CurrentDocument.GetValue("marketType").Replace("|", ", ") #%} started displaying the number of the item instead of the item name itself.
The list of choice has two parts "value,display". Your SELECT statement populate the value with ItemID which is number.
If you want to store the text, then it should be
SELECT '', '-Select-' UNION ALL SELECT marketType, marketType FROM BBUS_MarketType
populate the value with "marketType" instead of ID

Finding a value in a multi select list parameter in report?

I have a multi select input parameter for a report.
We know how to find whether a values is present in that parameter or not by using
$X{IN, colName, paramName}
the above expression in WHERE condition clause.
That is working fine.
But how will we find whether a variable ( let say having value 3 ) is present in parameter ( same multi select list let say [ 1, 2 ,3, 5] ) or not.
By validating the above condition i want to display something in report's static text field.

How to filter rows with null values in any of its columns in SSRS

I want to filter out the output without rows containing null values or blank columns. I am using SQL Server 2012 there is no option named 'Blank' as in SS2005 where I can filter the rows. I also tried following expression but it gives me error or not showing correct output
=IsNothing(Fields!ABC.Value)!= True
=Fields!ABC.Value = ''
Please suggest the solution.
Pull up the tablix or group properties
Switch to "Filters"
Add a new filter
Set the expression to:
=IsNothing(Fields!YourFieldHere.Value)
Set the type to "Boolean" (see screenshot below) otherwise you'll get a "cannot compare data of types boolean and string" error.
Set the value to false
This works for filtering both rows and groups.
We should use the isNothing method in the Expression, change the Text to Boolean
and then Value will be "True"
for example:
Expression
=IsNothing(Fields!TestA.Value)<>True
(Expression type should be Boolean)
Operator
=
Value
=True
Edit the SQL query, so that it will not return NULL values in the column to group on, but let it return a dummy value; for example: ISNULL(columnA, 'dummy')
In the column group definition add a filter: ColumnA <> 'dummy'.

Change Group Name in Crystal Reports to non-Database Value using Formula

I am looking to change the group names in a crystal report to a specified text value not located within the database.
e.g. i have a 'status' field that can either be 'i' or 'a'. I would like these to display as 'inactive' or 'active' in the group headings. The code i currently have in the 'Use a formula as group name' is:
stringvar newGroupName;
if (groupname = "I") THEN newGroupName:= "Inactive" ELSE
if (groupname = "A") THEN newGroupName:= "Active" ELSE
newGroupName:= groupName;
newGroupName
However this says i am passing too few arguments for the groupName reserved word.
Have looked on the net but have not found anything for defining non database names using the groupname function. Any help greatly appreciated.
Just to add, I always add a standard formula to the formula list to calculate the group names :
if {table.field} = 'I' then
'inactive'
Else if {table.field} = 'a' then
'active'
Else
'unknown'
Then in the group name formula in the group expert I refer to the formula like {MyGroupName}
This makes it much easier and quicker to edit the names but also will not be lost if you edit the group field (very useful if you have a large amount of code).
Make sure you pick fields from the window they will appear like {table.field} etc
There is no need for variable here just do something like:
if {table.field} = 'I' then
'inactive'
Else if {table.field} = 'a' then
'active'
Else
'unknown';