Microsoft SSRS 2016 Report Variable to Group data: Variable values cannot be used in group expressions - variables

I am building a report in Microsoft SSRS 2016; I have multiple groups in my report,
all these groupings are done via (the same) set of parameters. You can see the screen
shot below:
1) I have 3 groups in SSRS 2016 Report Designer.
2) All 3 groups use the same expression (using parameters) to group report.
In a nutshell, if the parameter value is X, it is grouped by X; if that parameter value is Y, it is grouped by Y; I do this for many groups, creating many parameter.
I will have many more groups in the future, and hence many more parameter options,as the report grows. I am trying to figure out a way to optimize this SSRS 2016 report by writing this code JUST ONCE.
I tried to add a Report Variable as shown below:
Now I have a new Report Variable (GV2) that stores this code with Switch operator.
I now try to use this Report Variable across many different groups.
I get this error:
Variable values cannot be used in group expressions
Is there any other way to do this? I need to optimize this sort of parameterized grouping.
May be writing some custom codes in SSRS; if so, can you provide the code (my knowledge in .Net is zero!)
Thanks

You can use a parameter to do this.
Set up a parameter for your group by options
In the Available Values, add the things you want to group by
For the value section of these, put the name of the field you want to group by. For example - if you want to group by Fields!Region_Name.Value, you set up your parameter with Region_Name in the value field.
In your group expression on the tablix, use =Fields(Parameter!GroupBy.Value).Value
Now when you select the value from the parameter, it will group by that. You simply have to add new values to the GroupBy parameter in the future to add more options.

Related

SSRS Chart Data - Filtering options for Values?

I'm currently running Visual Studio 2010 for reporting for pharmaceutical batch production. The system creates archive data table with the following fields:
-VARIABLE, which is the name of the variable,
-TIMESTAMP, the time when the value of the variable was recorded,
-VALUE, the actual value of the variable at a specific timestamp,
and so on.
The dataset I'm concerned with contains 3 variables: Level, BatchTimer, and BatchID.
Goal: What I want to achieve is to have Level as the Y value, BatchTimer as the X-axis(Category Group), and BatchID as the Series Group. Therefore I tried putting the VALUE field for all three regions, and adding filter options for the Category Group and the Series Group. Here are the filter options I added:
Filter Option for Category Group
Filter Option for Series Group
The problem now was filtering the Y value so that it only has field VALUE of Variable Level. I then assumed I needed to add a filtering expression to the value region of the chart data, which I don't know how to.
So my question is:
Is this the correct way to approach my goal?
If so, how would I go about filtering the Y value so that it only shows a certain variable in a dataset(in my case, Level)?
Thank you in advance!
If I understand your problem statement correctly, Your end goal is to filter out Level values, i.e For Example Level has values 1,2,3..10 but you want your Level values to be let's say only 3.
So return all data where level is 3. Once you have this datset, you are already able to add BatchTimer as the X-axis(Category Group), and BatchID as the Series Group.
You need a Parameter of a Filter in your dataset something like below.
Now above way is static for Level=3.
How do we make it dynamics
We create a Parameter and ask user to give level. Then depending on this parameter value we filter dataset as below ( this should be added to dataset query)
level field Operator: = and value of the parameter
(Parameters.level.Value)

SSRS 2008/2012 - ADDING AGGREGATION FIELDS

I'm attempting to add a field to an SSRS report based on 2 other displayed fields.
I'm using a matrix report
Field One is a Count of Account numbers
the Second Field is an Order Amount
My Attempt
New_field=(Sum(Amount))/(Count(Account))
What is the best way to do this in SSRS. Because one cannot have Aggregate functions in SSRS.
A second and related issue is Percent increases. What would be the best way to generate Percent differences in a new column.
Notes:
1. The report is fueled using a SQL Stored Procedure.
2. Graphical Display vs tabular are acceptable
Thanks
You can simply put your formula in query and give it an ALIAS. I've also use CASE statement to catch the error when Count(Account)=0.
SELECT
CASE WHEN Count(Account)=0 THEN (Sum(Amount))/(Count(Account)) END AS New_field
FROM TableName

Why can't Aggregate and lookup functions be used in query parameter expressions in SSRS?

I'm using an if to run one query if the user selects all from a multivalued parameter, and the other if not. So I figured I'd compare selected parameters vs rows in the data set.
However I get this error:
“The expression used for the parameter 'DataSet2' in the dataset
'DataSet2' includes an aggregate or lookup function. Aggregate and
lookup functions cannot be used in query parameter expressions.”
Here's the part giving the issue:
IIf(Parameters!SomeOptions.Count < COUNTROWS("SOME_LIST"), ….
Of course supplementing the COUNTROWS("SOME_LIST") with 15 (the value it returns)works fine.
Anyone know why this happens, and/or any work around?
Here's a workaround I use in the absence of an IsSelectAll flag:
Add another internal parameter called InternalParameter_SomeOptions.
Set the default value and available values to equal the same data set as SomeOptions.
Set your expression to =IIF(Parameters!SomeOptions.Count <> Parameters!InternalParameter_SomeOptions.Count, nothing, Join(Parameters!SomeOptions.Value, "|"))
If you have a multi-selection parameter whose data source is a dataset and you want to know if ALL was checked, from within your REPORT Dataset (like an SQL) to filter properly, look no further!
Why does this matter? Say you have a dataset (love datasets as data source for parameters btw, save em on the server for reuse over and over) for displaying a vendor list for users to select one or more (multi) from. What if that list is 10,000 long. You do NOT want to use: WHERE VENDOR_ID IN(#VENDOR). If the list is long enough, it WILL bomb and you will have to hunt the error down in SSRS log. So, this is one reason why we need to check if ALL was selected.
Create a new parameter identical to the dataset parameter(so they both use the same dataset and have the same default values), make sure to set it to multi selection and hidden (you do not want users seeing it). I name mine ---All where --- is the name of my parameter to easily distinguish.
For the dataset that serves as your REPORT data, add an additional Parameter. I like to call it #Is----AllChecked where ---- is the name of my parameter. It is named as a boolean (1 for true, 0 for false). In this example, it would be named #IsVendorAllChecked.
In the DEFAULT value expression check if the count of each REPORT parameter is the same (the one the users use and the duplicate), and return a value, like 1 if the same 0 if not. For example =IIF(Parameters!Vendor.Count = Parameters!VendorAll.Count, 1, 0)
In your REPORT Dataset, evaluate the parameter value and act accordingly in your SQL: where ( (#IsVendorAllChecked = 1 and vendor_id = vendor_id) or (#IsVendorAllChecked = 0 and vendor_id in(#Vendor)))
#Vendor obviously being the parameter the user interacts.
Always wanted to contribute.
SE: Report Builder check if all was selected
SE: Report Builder how to check if all was selected
SE: Report Builder parameter query expression cannot use aggregates

Edit Parameter Field Crystal reports with NOT value?

In Crystal Reports, I want to add a WHERE field <> date to filter out dates that have a NULL value from my database in my report.
I'm using a legacy FoxPro database on the backend which generates an SQL statement from my report, but doesn't appear to have anyway of adding a WHERE clause to the generated statement.
When accessing the FoxPro backend directly, dates with psudo-NULL values have a date of 1899-12-30, but when they are pulled from FoxPro through Crystal they appear as 12/30/99 (which is maybe the same date just displayed in MM/DD/YY format).
I noticed that the report had an existing Parameter Field that prompts the user to filter out the original query down to a specific date range. I tried to add my own in addition to the Parameter Field, but discovered that what I needed with my WHERE field <> date is not an available option since there are only 3 types of Field Parameters mainly:
Discrete
Accept single and discrete values.
Ranged
Accept a lower and upper value in order to select everything in this range.
Discrete and Ranged
A combination of the two above
None of these appear able to filter the results of the query using a WHERE NOT type of clause, is there some other way to do this?
Add this to your record-selection formula:
// remove actual nulls
AND Not(Isnull({table.date_field}))
// remove old dates
AND {table.field} <> date(1899,12,30)
// remove dates not in select parameter value
AND {table.field} IN {#date_parameter}
All I really needed to do was add some criteria to the WHERE clause of the SQL statement, simple enough in an SQL client, but when you're doing this in Crystal Reports v10 it's a bit difficult to find, unless you know what you are looking for...
So what I needed to do was:
Select the field to filter by in the report (in the Details section)
Click the Select Expert button on the Experts toolbar.
In the Select Expert dialog the name of your field should appear in a tab.
Below you can select the WHERE criteria used to filter the records.

SSRS Report , Dynamic selection of fields

I want to create a report where my report's fields should change according to my input parameter values.
For example, if I select 2 months, there should be 2 fields in result, having month wise calculation. If I select 3 weeks, there should be 3 fields each for each weeks calculation instead of the 2 months field.
How do I achieve this?
I'm still a beginner at SSRS, but I've heard of a few ways to handle this:
To a certain extent, you're really talking about separate queries, depending on the parameters. So, use a dynamic query (build the query up as a string expression). The simplest way I saw was to use IIF in the expression to choose one or the other stored procedure based on the parameter values.
To the extent that it's pretty much the same query, but you want different columns visible, then you can tie the visibility of the columns to an expression based on the parameter values.
If too much of the structure of the report differs based on the parameters, then you can use multiple reports. Have one front-end report that calls on one of the other reports based on the parameter values, passing the parameter values to the other report.
I hope that helps. If you've already figured out a solution, then please tell me!