Creating a Calculated Field between 2 datasets in SSRS 2008 R2 Express - sql

I have a very simple task. I have two datsets. The first is a single value that has returned me a number of calls that has been made. The second is a list of targets. I want to be able to divide the first number of calls by its call target in order to calculate the total %.
The lookups of these are dependant on the criteria that is selected in the report itself. I know it's possible to do inside SQL its just a huge pain in the ass. I want to be able to calculate two fields and I thought something so simple would be a breeze for SSRS but apparently not. So the error i get is:
*The expression used for the calculated field'=fields!DMCP.Value / FIRST(Fields!DMCTarget.Value,"AllTargets")' includes an aggregate,rownumber,runningvalue, previous or lookup function. aggregate,rownumber,runningvalue, previous and lookup functions cannot be used in calculated field expressions.*
I can take the first function out but it doesn't help me. It says it can only calculate in the same dataset, problem is these values can never co-exist in the same dataset. Anything I can do????
Thanks in advance

Related

Static Values from Multiple Queries/Datasets in Single SSRS Tablix

ok so I have this report I have to write in SSRS with a very specific format. It looks like the screenshot below at the bottom. Ignore the arrows and colors. It's pulling from an Oracle database. Each number value cell in this table/matrix has a different sql query to pull it in because they come from different tables, etc.
the top half of the numbers in the table are each from a query. the bottom half of the table is all calculations from the numbers in the top half. I already have the queries for the top half and was trying to figure out how I could just use those to make this table in SSRS with just those and then creating calculations in the bottom half for the report. I can't use a table or a matrix because each query is a different dataset and you can only have one dataset per tablix.
I was thinking maybe doing textboxes and drawing the grid manually, which would be a huge pain. I get errors about not having an aggregate and being out of scope or something and haven't figured out the reason for this yet as it is not my ideal solution.
My current solultion that will eventually get me there is unioning every single query and then creating columns with static values for the rows and columns in the grid and turning it into a matrix. Problem with this is it continues to increase in complexity as I create each further down the table calculation, and the code becomes larger and larger, and takes a long time to create, and I have to do like 6 reports similar in nature to the format of this one. Will probably be a thousand lines of sql and force me to have to make a stored proc because of the ssrs character limitation.;
So my question in a more simple way is, how can I take multiple sql queries that return a static value and make them a single value in a tablix that doesn't repeat, then create more blank rows in that tablix that are calculations of other cells values, i.e. Textbox1 - textbox2, textbox3/textbox4 ?
I got it figured out using expressions with multiple datasets. The answer seemed too easy once I found it. Basically just created a table tablix using my first dataset. Created more detail rows with insert row inside group below. Then I went to the expression builder for each one and found the other dataset and double clicked it to get the expression to pull from the other dataset. For example the bac_labor dataset value would look like this. =Sum(Fields!BAC_LABOR.Value, "BAC_Labor")
Then for calculations can use either same thing like =Sum(Fields!BAC_LABOR.Value, "BAC_Labor") + Sum(Fields!BAC_LABOR_OVERHEAD.Value, "BAC_Labor") or could do something like this =ReportItems!Textbox2.Value - ReportItems!Textbox1.Value to reference a cell value. This saves a ton of time, development effort, and reduction of code for calculations, compared to adding together 500 character select statements to make calculations. Also no need to use stored procs and union or join every select statement together with this method.

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.

How to add a field to a report that has groups

I need to add a field to a SSRS report. I tried modifying the dataset (query) but the results prouduced insane results, with zipcodes showing up in the name fields and names showing up in a datetime field. I suspect it is because of the groups but I don't understand how they work. The Dataset is created by 4 selects. The first 3 insert into temp tables and the fourth pulls from it. I suspect that I will have to re-write the query but it would be nice if I could use it as is with modifications. Either way I need to understand the groups.
I read
Data Region Cells, Data Region and Understanding Groups. Aside from the fact that they use terms specific to SSRS without defining them they are so undetailed I doubt many people who do not already understand SSRS can get anything out of them.
I did not write this report but I must modify it. I understand SQL well. Not so much with SSRS.
Can anyone explain how to find out what the Row Groups mean? Mine look like this:
Here is the tablix

Recreating Hyperion Reports in Access and SSRS (Microsoft Visual Studio 2012) using the Prior and Next Functions

I have several reports in Hyperion that I use the next and prior functions to look at the row right before and/or the row after.
To do this, I sort the data in a certain way to make sure the prior or next functions in hyperion find the right rows above or below the current row. For example, I may sort 2 other rows to get the right sorting for the functions to work correctly.
Now I would like to be able to find a way to recreate these reports in Access and SSRS.
I have been looking for a way to accomplish this in either or both. But at the moment I have not found a way.
If I need a unique field to help with this, I can concatenate between about 4 fields to make a column that has a unique key for each row.
Could anyone point me at a good article or know how to do this? I would really appreciate it very much, thank you!
Using sorting and grouping, probably similar to what you did in Hyperion, you can mostly accomplish this in SSRS using expressions:
FIRST() will return the first row of your current scope of data
LAST() will return the last row of your current scope of data
PREVIOUS() will return the previous row of your current scope of data, or NULL if there are no more previous rows.
Of course, what's missing is something like NEXT(). For whatever reason, Microsoft didn't see fit to include a NEXT() option. Instead, you need to grow your own solution. I see a few common strategies used for this:
A LOOKUP (or LOOKUPSET/MULTILOOKUP) function against your report dataset, combined with FIRST or ROWNUMBER to get
Write some custom code to do the sorting/indexing for you, see here for one idea: http://sqlreportsq.blogspot.com/2012/03/can-we-get-next-row-value.html
Do whatever data maniuplation in you need to do via your SQL using LAG/LEAD

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!