SSRS 2008/2012 - ADDING AGGREGATION FIELDS - sql

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

Related

Crystal Reports dynamic group summary

I'm trying to figure out a way to dynamically create a report summary that lists the totals of instances for each account dynamically at the beginning or end of the report. An account will only show up on the report if that account had any instances in the date/time range established by the Start/End date parameter fields, so every account will not always show, hence the dynamic part of the problem. There is surprising sparse information on how to do this from what I've found. Any ideas would be appreciated.
Use Insert, CrossTab...
Select Account as the row and select the value you wish to summarize.
There are many other options if you look into CrossTab features...

Trying to count records in SSRS from different data sets

I have an SSRS report that combines 5 reports into one. Each report is populated from a different stored procedure. The first page is a summary that is to provide a record count from each report. I've created fields in the stored procedure that provides the counts for each individual report: phycount and nonphyscount. I'm trying to create a table similar to this:
Active comes from one data set, Initial comes from another, Recert comes from another, etc.
I've been playing around with the Lookup and LookupSet but I'm just getting errors, plus I'm not sure if that's even the right direction.
Does anyone know how to do this?
Lookup and Lookupset are more for getting specific values out of a dataset. Very useful but not necessary for what you're trying to accomplish.
You can use aggregate functions SUM and COUNT to accomplish what you want to do. The cool thing about these functions is you can actually embed IIF statements inside of them.
I'm not sure exactly how your datasets look and are named but it would be something like this...
SUM(IIF(Fields!Type.Value = "PhyCount", 1, 0), "Active")
The sum function goes through every row of your dataset and sums the values you pass to it. The iif statement checks to see if the type field in the dataset is "PhyCount". If so, it returns 1, if not, 0. Since this will happen for every row, your SUM function will return a count of each row with status active.
edit: "Active" after the iif statement specifies the name of the dataset.
EDIT AGAIN: This solution apparently does not work in SSRS 2008.

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

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.

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!