SSRS Report- Using two data sets - sql

I want to do a calculation using two different datasets, but I cant seem to do it in the expression field. Any ideas on how I can add, multiply or divide using the two datasets? In the Fields, I added a new one and trying to set the expression only gives me DataSet1, but I want to add a DataSet2 field and a DataSet1 field.
Thanks guys

You can not directly use two data sets in there.
Imho you should move your data to db queries, then add a query that does your job, include this in your report then.
Alternative you can calculate some aggregat in a field, hide the field, do this with more/many as you want, then use your operatores on the result fields.

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.

Get Sum of Data from Second Dataset in the Second Tablix of SSRS report with Report Builder

I have two different dataset which has a common value placed in two different Tablix in Report Builder tool. I want to achieve a SUM of ELEC_DATA in the second Tablix.
I have already tried using this expression.
=LOOKUP(Field!COMP_ID.value,Field!COMP_ID.value,Field!ELEC_DATA.value,"DATASET2")
The result shows nothing at all -- no errors as well.
Then I tried with custom code.
=code.sumlookup(LOOKUPSET(Field!COMP_ID.value,Field!COMP_ID.value,Field!ELEC_DATA.value,"DATASET2"))
The Result I am getting is "0".
The expected result would be the addition of ELEC_DATA like shown in the pic attached
Looks to me like you're using the LOOKUP function incorrectly. The LOOKUP function only requires 4 parameters to be used.
=LOOKUP([SourceValue], [DestinationValue], [LookedUpValue], "[SourceDataset]")
However, I'm not sure this is the best or even a viable solution to your issue. Honestly, this would be much easier if you were able to combine these two datasets into a single dataset query.
SELECT PAC2_ID, A.COMP_ID, DATE, ELEC_DATA
FROM TABLE1 A JOIN TABLE2 B ON B.COMP_ID = A.COMP_ID
From there, you can use a Grouping on the second Tablix based on PAC2_ID which removes the need for any expressions. It should sum the values automatically when you apply the grouping.
Alright Let's try something like this.
In your 2nd Tablix create one more Column let's call it "PAC2ID_Calculated".
Now for this Column we will use lookup Expression =Lookup(Field!COMP_ID.value,
Field!COMP_ID.value,
Field!PAC2_ID,
"FirstDataset")
Now what will this return in your new Column, It will return PAC2_ID for COMP_ID from first dataset and your 2nd Tablix will be something like below
Once you get this, Group it based on PAC2_ID, you will get expected Result.
You can Hide COMP_ID column.

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

how to Select fileds in different dataset from Different DataSource

i have two Data Sources. Each DataSource has some DataSets. What i want is a tablix to retrieve data from different datasets of those two DataSources. But it seems like that in a tablix i can just select one datasource at the same time. I cannot change datasource after select it.
I've tried the sql for each DataSource, there is no problem. But i have no idea about how to select different datasets from two different DataSources.
Appreciated for any suggestion!
You can select from more than one datasource if you use the expression editor for each field's value.
In the editor, click on "Datasets" in the lower left box (called "Category:"), and choose the dataset you want to get the value from in the lower middle box, and then in the lower right box, choose the field from that dataset that you want to get.
You will have to choose some aggregate function on the field, because when you use multiple datasets this way, you can't expect the tablix to be able to populate one table row per data row. But if your dataset only returns one row, you can simply use the First() function for pretty much any value you want to get.

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!