I am having a problem using Lookups in a ssrs report. The report takes in 3 datasets that I do not have the opportunity to edit or merge (three different cubes)
It is a sales report that should be grouped by Sales Manager and show the potential for sales and a "discounted potential" of sales. The problem I face is that I have to loop my table on DataSet1 since it is the only on that holds Sales Mangers.
Using LookupSet and LookupSum it is easy enough to get the potential from DataSet2. Something like:
=Code.LookupSum(LookupSet(Fields!Country.Value, Fields!Country.Value, Fields!Potential.Value, "DataSet2"))
The problem arises when I try to calculate the Discounted Potential form DataSet3
Namely because I need to perform the lookup based on a value that is not in DataSet1! Is this somehow possible?
The datasets and the desired report look like this
You should be able to change the dataset of the tablix to DataSet2 to get the desired results. Dataset2 is the only dataset that directly relates to both of the other datasets, and since nested Lookups are not allowed, and also since you cannot modify your datasets, this is necessary for this situation.
I'm not sure exactly what calculation you are using to end up with your "Discount" column, I couldn't figure out any formula that worked with all of your sample data shown. For my test I just took the Sum to make sure it was working, but you should be able to modify that to fit your needs.
I set up a tablix like so:
+---------------------------------------------------+
| Manager | Country | Potential | Discount |
| <Expr1> | [Country] | [Sum(Potential)] | <Expr2> |
+---------------------------------------------------+
With 2 row groups, the first grouping on Expr1, and the child group grouping on Country, where Expr1 is =Lookup(Fields!Country.Value, Fields!Country.Value, Fields!Manager.Value, "DataSet1") and Expr2 is =Sum(Code.SumLookup(LookupSet(Fields!Customer.Value, Fields!Customer.Value, Fields!Discount.Value, "DataSet3"))). I sorted the parent row group by Country to keep the sorting the same as you had it in your screenshot. Again though, you would likely have to modify Expr2 to fit your needs. If the discount is a percentage for that particular customer, then the following code should work for that, but the results don't match your screenshot so I'm not sure if this is what you are looking for:
=Sum(Fields!Potential.Value - (Fields!Potential.Value * Code.SumLookup(LookupSet(Fields!Customer.Value, Fields!Customer.Value, Fields!Discount.Value, "DataSet3")) / 100))
Results from using the modified Expr2 if Discount is a percentage:
Related
I have two datasets and I'm using Lookup to get one result, but the total is only from one dataset. I've tried and tried, but I'm having no luck.
First Dataset is called MedCond
This is the Data:
Drug_Name
Start_Date
Stop_Date
InmateID
Drug_Indication
Created
ID
Second Dataset is called ProblemList
This is the Data:
Medical_Condition
Inmate_ID
Created
ID
Drug Indication and Medical Condition are the same. I want to get a combined total of both.
This only gives me the count of the Drug Indications (which I have them grouped on) =Count(Lookup(Fields!Drug_Indication.Value,Fields!Medical_Condition.Value,Fields!Medical_Condition.Value, "ProblemList"))
I feel like I've tried everything under the sun. I'm extremely exasperated. I'm trying to get a total of each of the conditions/Indications that come from each dataset. For instance, One condition/Indication might be Addiction. There may be four addictions in from the Drug_Indication in the MedCon dataset and five addictions from the Medical_Condition in the ProblemList. I want to see Addictions 9 on the table and so and so forth for each Drug Indication/Medical Condition.
Thanks in advance for your help! Save my sanity. :) I'm sure it's probably something simple?
Tara
Thank you. I've tried using the Inmate_ID and InmateID as the key to join, but I still end up with only one of counts of either Medical_Condition or Drug_Indication.
As an example, there might be 10 addictions in one and 15 addictions in the other. I need them to be grouped under the title addiction (and whatever other titles there might be) with the total being 25.
It would look something like this.
Example Look
Something like this is close, but the counts aren't quite right.
=Count(Lookup(Fields!InmateID.Value, Fields!Inmate_ID.Value, Fields!Medical_Condition.Value, "ProblemList")) + Count(Fields!Drug_Indication.Value)
Maybe it's the way I'm grouping? How do you group on a combination of values such as Medical_condition and Drug_Indication?
Thanks again!
Tara
I think you used the Lookup() wrong. When I look at your two datasets (for me) the key to join the two datasets would be Inmate_ID.
=Lookup(Fields!InmateID.Value, Fields!Inmae_ID.Value, Fields!Medical_Condition.Value, "SecondDatasetName")
This would result in a table like this (The last column comes form the lookup above):
Drug_Name | Start_Date | Stop_Date | InmateID | Drug_Indication | Created | ID | Medical_Condition
Now you can just get the total per column:
Drug_Name | Start_Date | Stop_Date | InmateID | Drug_Indication | Created | ID | Medical_Condition
Total1 Total2
To sum Total1 and Total2 you can add a new tablix and reference to the textbox totals like this:
=ReportItems!Total1TextboxName.Value + ReportItems!Total2TextboxName.Value
I am working on a report to show the total number of hours an employee spent working. Our company tracks labor hours by Service Request and Work Order so I need to bring totals for each into the report.
I created two datasets- one for Work Orders and one for Service Requests. Ideally, I would like to combine the total number of Work Order hours with the total number of Service Request hours and present that number listed by employeeID since both datasets have the employeeID field.
I thought it would be as simple as:
=(SUM(Fields!TOTALHOURS_WO.Value, "DataSet1") + SUM(Fields!TOTALHOURS_SR.Value, "DataSet2"))
I don't get an error, however, I am getting a number which repeats for each employee so I know I'm doing something wrong.
Any help is greatly appreciated.
Mal,
As #StevenWhite mentioned, LOOKUP is probably the function you are looking for.
Here is an example for you. For the example datasets:
EmployeeID | TOTALHOURS_WO
-----------------------------------
123 | 12
456 | 3
EmployeeNum| TOTALHOURS_SR
-----------------------------------
123 | 2
456 | 5
You will note that each table in a SSRS report needs a DataSet assigned to it. I will assume your table is using our first DataSet, which we will name "DataSet1". The second dataset above will be "DataSet2".
For your total hours you will use an expression. It should look something like this:
=TOTALHOURS_WO + LOOKUP(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, Fields!TOTALHOURS_SR.Value, "DataSet2")
So you will be adding the TOTALHOURS_WO from your local dataset to the result from the LOOKUP function. What lookup is doing is taking the first field from your local dataset, finding a match in the dataset provided to the function (as a string), and returning the field from the row it matched to. The last parameter is the dataset to search.
Just in case you get an error... it's always a good idea to cast data to the type you want to work with in case it comes in wrong. So...
=CINT(TOTALHOURS_WO) + CINT(LOOKUP(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, Fields!TOTALHOURS_SR.Value, "DataSet2"))
This assumes you have a one to one match on employee ID. If you have to SUM both fields you can try this:
=SUM(CINT(TOTALHOURS_WO)) + SUM(LOOKUPSET(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, CINT(Fields!TOTALHOURS_SR.Value), "DataSet2"))
SUM for TOTALHOURS_WO will give you the SUM in your current table group (so make sure you are grouping by staff ID in the table). It will then add it to the SUM of LOOKUPSET. LOOKUPSET works the same as lookup but returns an array of matches instead of the first.
Hope this helps.
I got a request from the client when using SSRS reporting Service. I am kind of new to the SSRS. hope that someone can help me out with the problem below.
I use a common example to show the problem.
In SSRS dataset1, the data is like follows
StuId StuSubject
--------------------------------
1 "Math"
1 "Geography"
2 "Science"
3 "Math"
3 "History"
3 "Music"
In the SSRS dataset2, the data is like this one
StuId StuName
------------------------
1 "Tom"
2 "Joseph"
3 "Linda"
In the SSRS DataSet3 , it would be like
StuId StuInt
--------------------------
1 "Swim"
2 "Chess"
2 "Swim"
2 "Running"
3 "Game"
What i want in the SSRS report would be like this one
StuId StuName StuSubject StuSubject StuSubject StuInt StuInt StuInt
1 "Tom" "Math" "Geography" NULL "Swim" NULL NULL
2 "Joseph" "Science" NULL NULL "Chess" "Swim" "Running"
3 "Linda" "Math" "History" "Music" "Game" NULL NULL
The tricky part is that I don't know what is the maximum number of StuSubject for all these students, or more precisely, I don't like to set the limit of the 'StuSubject' columns because there could be hundred columns in the real case. I have thought of LookupSet function, but seems using LookupSet, you can only join multiple StuSubjects values with "," in one cell.
Any advice / suggestion would be much appreciated and thanks in advance
Edit : I could use Matrix control for one "join" situation, but is this possible to "join" multiple datasets into one finale one ?
The solution for you is to use Matrix report item - it allows to perform data grouping by rows and columns. Your data, returned from DB, should be aggregate of those two datasets that you have - it should be set of rows in format (StuId, StuName, StuSubject).
You can then add row grouping by StuId (and child row grouping by StuName, but this is not necessary), and add column grouping by StuSubject. Details cell will simply output StuSubject.
Notice that although Lookup* functions allow you to do join data while processing the report, they are run while processing report by SSRS and thus are certainly less efficient (from my experience expressions almost always have really bad impact on report performance). Also, doing join whikle processing report is not a canonical way to develop the report, and not the best way to use SSRS engine, which works good when you need simple grouping or do not need grouping at all. The best approach is to generate SQL result as much close to what you want to display, as it is possible, taking into account context of report and common sense of course.
Follow the below steps:
Use your DataSet1 in your matrix as suggested approach from LINK.
Your query would be similar to below:
Select StuId,StuSubject
'StuSubject' + Cast(row_number() over (partition by id order by score) as INT) StuSubjectVal
from table
You should get the result like below (after using matrix).
StuId StuSubject1 StuSubject2 StuSubject3......
Add a column to your matrix, and use the Lookup from DataSet1 to DataSet2.
=Lookup(Fields!StuId.Value, Fields!StuId.Value, Fields!StuName.Value, "DataSet2")
Have not tested it, but it should work.
I am a rookie to SSRS and am having difficulty obtaining a Sum.
I want the cell to Sum the distinct values of "UnitNumber" which is what the report is using to generate each row of my table. The reasoning behind this is that behind the complex report, Unit numbers are distinct and provide me with distinct SqFt Values. For example:
Unit # | Sqft|
Unit 001 | 472 |
Unit 002 | 600 |
Unit 004 | 1203|
The below does not work:
Sum(IIF(Fields!Unitnumber.Value,1,Fields!SqFt.Value)
I either get "Contains an error: cannot be converted to String" or, #Error in the cell. I cannot solely use Sum(SqFt) because it dumps an aggregate of the whole dataset query (every single row summed up) Any ideas?
It seems that your IIF missing main condition. It can be something like below or do as per your requirement.
Sum(IIF(Fields!Unitnumber.Value=1,1,Fields!SqFt.Value)
Also, I would suggest you to make your expression like below,
=SUM(IIF(Fields!Unitnumber.Value = 'putyourcondition', Fields!SqFt.Value, 0))
I am building a report in report builder. I have 2 dataset, they can't be merged because of their complexity. What I would like to do is make a report where it use the ID from the first dataset to look up data in the 2nd dataset. Is this possible? The following are example, not exact code, but what I need:
First Dataset:
select itemID from Items
Second Dataset:
select itemID, saleAmount, salePrice from Sales
I would like to setup my report like this:
ItemID | Sale Count | Sale Price
--------------+-------------------------------------------------------------+------------
Items.itemID | sum(Sales.saleAmount) where items.itemID = Sales.itemID | sum(Sales.salePrice ) where items.itemID = Sales.itemID
So the end result will be like this:
ItemID | Sale Count | Sale Price
--------------+-------------------------------------------------------------+------------
1 | 11223 | $123123
2 | 4537 | $8375
Is this possible? Maybe with Conditional Lookup?
It's a shame you can't join the data when creating the datasets.
Failing that, I can think of a couple of other options:
Use LookupSet and custom code
This excellent answer How to combine aggregates within a group with aggregates across groups within SSRS has a perfect example of how you might do this.
Basically, you add custom code in a function (e.g. SumLookup) that accepts the results of a LookupSet call and returns the aggregated value. You'd have expressions like the following in your report:
=Code.SumLookup(
LookupSet(Fields!itemID.Value, Fields!itemID.Value, Fields!saleAmount.Value, "Sales")
)
I created a quick test and it works perfectly.
Use subreports
To do this you'd create table based on the Items dataset, then in the detail row you'd embed a subreport to display the Sales information.
The subreport would need an itemID parameter to filter the Sales appropriately, you would set the parent table to pass =Fields!itemID.Value to the subreport - this would then repeat for each itemID row and display the relevant Sales data.
For what it's worth, I'd look at the first option - there is some custom code, but it's straightforward, and that way you wouldn't need to deploy multiple reports. Just seems cleaner to me.