SSRS Compare Two Datasets For Missing Ids - reporting-services

In SSRS report I have two data sources from two different servers. I have a dataset for each data source and would like to return in a tablix the ids that are in dataset 1 but not in dataset 2.
So if dataset 1 has ids 1,2,3,4,5 and dataset 2 has ids 1,2,3 the report should display 4 and 5. I cannot link the servers. Thanks.

There are several ways to do this.
Common Lookup method
This is the way most people would probably do this
Use the Lookup() function.
Set the tablix row's hidden property to something like
=ISNOTHING(
Lookup(Fields!IDa.Value,Fields!IDb.Value,Fields!IDb.Value,"Dataset2")
) = False
The above, for clarity, assumes the ID column in dataset1 is called IDa and the ID column from dataset2 is called IDb. It will stil work if they have the same name (e.g. 'ID')
Note: Dataset name must be in quotes and is case sensitive.
Using this method returns all the rows and simply hides the ones that do not match your criteria. This may not be ideal if you're exporting the data. If not, see the alternative version below.
Alternative method
For reasonably small datasets - parameter method
... and because I thought it was an interesting approach...
This second method uses a hidden parameter and is easy to setup assuming you have a reasonable small number of records.
Using your example, create a parameter called List2 and set its default and available values BOTH to your Dataset2 query (from your example above). Make the parameter multi-value. You can make this parameter hidden once it's working.
Now Your Dataset1 query can be a simple query like this,
SELECT * FROM Table1 WHERE id NOT IN (#List2)
#List2 will contain the values from datset2 (1,2 and 3) so the query will return only the remaining values.
Note I named the datasets to match your example but the datasets must be created in the order above.

Related

Display selected values of multi-value parameter in tablix rows

I am designing a report for SSRS. I want the user requesting the report to be able to specify, when they generate the report, from a pre-defined selection some values which should be displayed in a tablix on the report.
I have therefore created a multi-value parameter and populated the Available Values with the options I want the user to be able to select from, and, as expected, when the report is generated the user is able to select one or more of these values.
However, what I now want to do is include a tablix in the report, and display a row for every value in the multi-value parameter that the user selected, with the value displayed in the first cell of the row.
If the values were coming from a data table this would obviously be easy. I've also found answers on how to show all of the selected parameter values in a single textbox using the JOIN function, but I don't want to do that.
The only solution I can think of is to replicate the list of available values in the multi-value parameter in a tablix manually, and link the visibility of each row of the tablix to the selected state of the corresponding value in the multi-value parameter, but that's not very elegant and increases the effort involved in maintaining the report definition.
Any ideas on how to do this? I know the selected values from the parameter simply form an array, but I can't see how to bind a tablix to any data that isn't in a dataset, or how to create a dataset from the parameter values.
Considering that a tablix sources from a dataset, I did some experiments to see how to create a low maintenance solution for you.
Option 1: Create a data set with hard-coded options to match your multi-value parameter and select those options WHERE they exist in the parameter.
Example:
SELECT val
FROM (
SELECT 'opt1' as val
UNION SELECT 'opt2'
UNION SELECT 'opt3'
UNION SELECT 'opt4') a
WHERE val IN (#Param)
Thoughts: easier to maintain than visibility on a table, but still two hard-coded places within the report.
Option 2: Create a dataset that selects the multi-value parameter and splits it by each value. This was my first idea, but I ran into some issues with determining how to actually select the multi-value without a syntax error. I came up with a method that creates a deliminated string in the report and than parsed that string back into rows in the dataset:
Step 1) Within the dataset properties, on the parameter tab, join the multiple values together with a JOIN expression
Step 2) Create a simple query which uses the new SQL Server 2016 function string_split. Note that your database compatibility level MUST be 130 or higher to use this function (SQL 2016+). If this isn't your scenario, there are many string split functions that you can find on Stack Overflow to achieve the same thing.
Fun problem!

Add filter option on each column of the data displayed in SSRS

I am generating a table in SSRS based on the selection made by the user on two filters: Filter1 and Filter2 (say). The table so displayed has 10 columns and I wish to add filter option listing all available values for that column for all 10 columns.
Basically, I am trying to replicate the Excel functionality of filtering down data on each and every column.
Please note that I tried creating a new data set and a parameter taking all distinct values for a particular variable. However, I am still not able to get the desired results by filter the tablix on that parameter
Is there a way I can do that?
You'd need to make a new dataset that is a smaller version of your main dataset. It would need to return all potential values for the column(s) you want to filter in a single column to be used in a parameter.
Without seeing the design of the report or the dataset itself it's quite hard to be more specific.

SSRS dynamic data retrieval from another dataset

I want to get data(dynamic) according to the data in another dataset and put the result in textbox of the different dataset.
Right now, the data I get is static and I tried to use many expressions but no avail.
Problem lies in editing textbox expression. Since I am getting data from different dataset, it always ask me to have dataset aggregate function in my expression. If I specified the dataset from where I am getting the data, then, I cannot make it dynamic - and I get the undesired result.
And another way out that I attempted is merging the data sets into one rather than having multiples and use it only but this was unsuccessful.
How can I make it work to get the result that I want:
By the way, the textbox and the tables are in different scope. I have tried to combine them in one scope too.
Getting data from another dataset requires an aggregate function because it can't tell what data you want from that dataset so it forces you to aggregate it so it can return a specific value rather than an entire list of values.
I think what you are after is the Lookup function. Lookup allows you to look up a value from another dataset based on a value in the table's dataset. To give a simplistic example, let's say your table was of employees and you had a department id on that table and another dataset called "Departments" which had an id and a name. You could look up the department's name using the following expression:
=Lookup(Fields!DeptId.Value, Fields!Id.Value, Fields!Name.Value, "Departments")
This uses the current table's dataset's DeptId field to look up the Departments dataset by the Id field and return the Name field.
=Lookup(First(ReportItems!EmpID.Value),Fields!EmpID.Value,Fields!Dept.Value,"dataset_which_u_retrieve_the_data_from")
Problem solved!By using reportItems instead of Fields because I am retrieving one data only,not the whole field.
Thanks guys for helping me out.

Get value of table row

I've got two tables binded to two different datasets. I'm trying to reference one of the rows from one of the tables (Table A) from Table B.
Since it's outside the scope of the table, I can't use ReportItems![Textbox name].Value
Any ideas?
You can use the SSRS Lookup() or LookupSet() function to retrieve the data directly from the other dataset.
I found the MSDN pages a bit unclear, the syntax goes like this:
=LOOKUP(Fields!sourceMatchingField.Value,
Fields!targetMatchingField.Value,
Fields!targetReturnField.Value,
"Name of Second Dataset"
)
Fields!sourceMatchingField.Value is from the dataset that is
currently in scope.
Fields!targetMatchingField.Value is from the other data set you need to get information from and equals Fields!sourceMatchingField.Value.
These two parameter values for the Lookup function make the join criteria for the two datasets. They can be more complicated than simply two field references (such as using functions to manipulate on or both), but I'm just showing the simplest way to do it.
Fields!targetReturnField.Value is the field from the second dataset that you want to return. This should just be a reference to a field.
"Name of Second Dataset" is just what you've named the other dataset that you're joining to.

SSRS to display non aggregated numbers

I'm trying to built a report in SSRS where I can display all the skus available to one product in different store.
The only problem is when I do so, it generate a new row for the same product for a sku located in another store.
I would like to regroup them on the same row.
Any idea??
You'll need to add a row group to group by whatever other fields you need in the group, and then for your merged SKU field you can do something like:
=JOIN(LOOKUPSET(Fields!CandidateField.Value, Fields!CandidateField.Value, Fields!SKU.Value, 'DataSet1"), ",")
Replace "CandidateField" with the name of a field that can be "joined" back to itself (this is done by the LOOKUPSET() function) to produce the collection of SKUs you need for each row group. Also replace "DataSet1" with the name of your dataset.
And you can replace the comma with whatever delimiter you want.
The JOIN function is what is concatenating the values together; LOOKUPSET() is providing an input array to it.
Note that this only works in SSRS 2008 R2 or newer.
EDIT: Note that this is one means of doing this via SSRS; you could also handle this in your SQL if you'd prefer.