LookupSet function referring to entire data source and not following table grouping - reporting-services

I have the following information coming through in my data set -
I have it linked to a data table that is grouped by cust_code and site_id
I have a lookup set function in that table, with the goal being retrieval of all child_id for a given site_id in a table already grouped by cust_code.
However, the lookup set function points to the dataset as a whole, ungrouped, and instead is returning all child_id.
So basically, in this example, I am looking up based on '55' and it is returning all values assosciated to '55', rather than just the '55' value associated with that particular customer.
How can I get the lookup set function to follow the same grouping as the table cell it resides in?

Related

Plot total number of users by date joined

Is there any function or node which will add the number of elements in a set chronologically?
I would like to create a simple line graph of "total number of users" over time, but what I have is "user_email" (unique) and "date_created" for the date the user joined.
What is the easiest way to sum the number of users at any given time from their creation date and plot it in a graph according to time?
I tried searching for this, but didn't find anything related. New to KNIME. Thanks.
If you are sure that user_email only contains unique values, you can sort the table by date_created (if it isn't already sorted) then use a Counter Generation node to add a column containing a counter value.
For a more general solution, if you want to count the cumulative total of unique values in a table column, you can use this sequence:
GroupBy configured to group by the column whose unique values you want to count and to aggregate on the column you want to plot this against - for example, your timestamp column, probably with either the First or Last aggregation method
Sorter to sort on the aggregation column from GroupBy
then Moving Aggregation with the Cumulative computation box checked, and configured to aggregate on Count of the grouped column from GroupBy.

Table Joining (ms Access, sql)

Hoping I’ve not over simplified things,
I have 2 tables: tblTestA and tblTestB
Both tables are linked through their common ID fields.
I’m looking to select all records from tblTestA that have a date greater than #2013/01/01# its Date field.
Then, from this record set, further filter by keeping only those records who have at least 1 non-Null value in Field1 or Field2 from tblTest2 (i.e. remove double Nulls)
Is there a way to modify the following unworkable/pseudo code so that the above is achieved?
SELECT tblTestA.ID, tblTestB.Field1, tblTestB.Field2
FROM tblTestA
WHERE tblTestA.Date > #2013/01/01#
Inner Join tblTestB
On tblTestA.ID= tblTestB.ID
Where (Not IsNull(tblTestB.Field1)) Or (Not IsNull(tblTestB.Field2));
In the real scenario (due to the way the tables are structured, their size, and additional factors) querying only on the non-Null requirement takes very long. Querying only on the date greater than #2013/01/01# requirement takes very little time. So I’m thinking that if we can return the smaller date requirement result set and then use the common ID field to do the second filter on the non-Null check, then, the whole query might complete faster.
Edit:
Modifying the above to...
SELECT tblTestA.ID, tblTestB.Field1, tblTestB.Field2
FROM tblTestA
Inner Join tblTestB
On tblTestA.ID= tblTestB.ID
WHERE tblTestA.Date > #2013/01/01#
AND
(Not tblTestB.Field1 Is Not Null) Or (tblTestB.Field2 Is Not Null);
...returns records that are within the required date range but seems to also link the non-Null filter to that same date range. Entries for Field1 and Field2 may have been entered before the date range requirement filter. I've probably over simplified things from the real scenario, but I'm looking to do 2 things: 1. return records within a date range, and 2. from this result set, filter out any records that do not have at least one non-Null value in Field1 or Field2 from any date range.

SSRS Multiple Value parameter filter based on dataset

Say I have a dataset in SSRS called DataSet1 that looks like this:
CREATE TABLE #data
(ID int, Value int, UserID varchar(2))
INSERT INTO #data VALUES
(1, 1000, 'AA'),
(2, 2000, 'AA'),
(3, 3000, 'BB'),
(4, 2000, 'BB'),
(5, 1500, 'BB'),
(6, 1800, 'BB'),
(7, 1700, 'CC')
..and that my report just presents this as a table.
Let's then say I want to add a parameter in that report, that let's the user filter the table by UserID. I want it to be a multiple value parameter where they can choose which users to include in their report. In this case I want the list to be AA, BB and CC.
So far I have done it by creating an extra SQL query based dataset like this:
DataSet1:
SELECT ID, Value, UserID
FROM table
DataSet2:
SELECT DISTINCT UserID
FROM table
And then have the parameter get its available values from DataSet2. However the query I have in my particular report is a very long and complex query, that I would prefer to not use in two datasets. If I have to go back and change something in the query, I would have to maintain that in two places, and so on.
In short: Is there a way to have the available values of my parameter by something like this:
SELECT DISTINCT UserID FROM DataSet1
Thanks!
I decided to write my comment on your answer, M.Ali, as an answer to my own question, as I found a way to solve this. Maybe I didn't explain my problem precisely enough. I am aware of how the above thing works, and how to pass parameters based on one dataset, down thru the SQL to create another dataset, multiple values allowed or not. I appreciate your answer though!
The problem I have is that the query that would define my list of values for the parameter, and the query for the actual dataset, are the same. And it's a HUGE query. In other words, where it says 'TABLE' in the code sample, I have several hundreds of lines of code. And my goal was to not have this whole query be defining both datasets. If I in the future have to change the query, I would have to do it in more than one place. Here's how I solved it:
I placed the main query in a shared dataset instead of embedding it into my report. And I then added a row_number function to my query like so:
SELECT ID, Value, UserID, rn = ROW_NUMBER() OVER(PARTITION BY UserID ORDER BY UserID)
FROM *my huge query*
This means that there is only one 'rn = 1' row per UserID. Then I went back to my report. My original DataSet1 would then just point to the shared dataset. The DataSet2 (the parameter one) would also point to the shared dataset with the one difference that I added a filter to that dataset saying 'rn = 1'. I then made a parameter with 'allow multiple values' that took its values from DataSet2. And it works like a charm. This way I can just go to the shared dataset when I need to update the query, and both DataSet1 and DataSet2 will be updated accordingly!
Success :)
Again, thanks for your answer!
You will have to have a separate data set for your parameter query and yes you got that part right, for the given data set:
SELECT DISTINCT UserID
FROM TABLE
This query will be used to populate the drop down list of your parameter. (Multiple values allowed or not).
For you Main query:
if you allow Multiple Selection for #UserID parameter you will write you main Data set query with IN operator as below:
SELECT ID, Value, UserID
FROM table
WHERE (UserID IN (#UserID))
If you only want users to be able to select only one value at a time the you can write the above query with a where clause something like WHERE UserID = #UserID.
Make sure you map the variables correctly. But you will have to have a separate query for your drop down list.

Lookup function in SSRS report

I have one dataset Dataset1 and in that I am displaying data based on grouping. The data is like this
CityColumn CountColumn
City1 5
City2 3
The query of above datase is like this :
select count(*) as "CountColumn" from City group by CityColumn
Here in above dataset I have counted using grouping on CityColumn.
Now I have created another Dataset Dataset2 and in that The data is like this
CityColumn
City1
City2
City3
Now in dataset2 I have add one calculated field called TotalCount and used the Lookup Function the function is like this
=Lookup(CityColumn, CityColumn, CountColumn, "Dataset1")
but It gives me an error like
Lookup includes aggregate, rownumber, runningvalue, previous or lookup function. Aggregate, rownumber, runningvalue, previous or lookup function cannot be used in calculated field.
The first two values of the lookup function must refer to an identifying value in a column. In your case the City names must be in both datasets. Think of that as a primary key. The third value is the one you want to display from the second dataset. So it should look more like this:
=Lookup(Fields!CityColumn.Value, Fields!CityColumn.Value, Fields!CountColumn.Value, "Dataset1")
Make sure that Dataset1 has the column named CountColumn that you are trying to lookup. Keep in mind that this only looks up individual rows, not aggregates. If you want to work with aggregates you can do that on top of the lookup function.
EDIT:
Since Lookup functions are not allowed in calculated fields, you'll need to use it in the Value expression in your pie chart. It should look like this:
Note that the lookup function has to be in an aggregate like a sum function for it to work as a chart value.
Instead of adding it as a calculated field in the DataSet, simply add the expression into an empty column within the details rows of the report.

Two datasets issues in ssrs?

I have a column name 'APPs % of total' and it requires two different data sets to be populated .This doesn't seem to work. Any tips will be appreciated. Thanks
=(Fields!AppQty.Value/Fields!AppQty.Value,"second dataset")
The problem is: how does SSRS know which row to pull from the second dataset to get the field? So you have to use aggregation or lookups:
Method 1: Simply aggregate at the current level
There's usually no need for a secondary dataset just for your sums. You can aggregate at the group level within the current dataset by using the following formula:
=Fields!AppQty.Value / SUM(Fields!AppQty.Value, "table1_Group1")
where table1_Group1 is the group where the data is summarised.
Method 2: Aggregate the entire dataset
Aggregate at the dataset level for the either the current dataset or a secondary one:
=Fields!AppQty.Value / SUM(Fields!AppQty.Value, "SomeDataset")
Method 3: Lookup the value from another dataset
You'll need a dataset that sums the values at a group level. You usually achieve this result using method 1 and grouping, but here for completeness. So, let's say you are grouping by DepartmentId, you would have a dataset that aggregates like so:
SELECT DepartmentId, SUM(AppQty) AS AppQty
FROM MyTable
GROUP BY DepartmentId
Then lookup the appropriate value for the department from the current row (in the current table's dataset):
=Fields!AppQty.Value / Lookup(Fields!DepartmentId.Value, Fields!DepartmentId.Value, Fields!AppQty.Value, "SummaryDataset")
So the Lookup matches the DepartmentId from this dataset with the DepartmentId in the SummaryDataset and returns the AppQty value.