Solved

SSRS Report Design Question - drill down / sub report

Posted on 2014-02-25
6
800 Views
Last Modified: 2014-03-05
Hi, i am relatively new to SSRS, and an dusting off my SQL skills, so i may be missing an obvious solution here. But right now i am stuck in finding the best way to display some data in a tablix.

I have two main tables, contracts and subcontracts. This is a report by salesperson which shows what they have sold over a given timeframe.

From my contract table, i have the main info, i have the subcontract id, salesperson id, invoice, id. Subcontracts shows the details of exactly what was sold, and when. there can be multiple subcontracts. my issue is when i join to the subcontracts table, i get multiple rows in my result per contract, which creates a problem for the contract amount. the contract amount is repeated in each row, and when SSRS subtotals it the numbers are way high.

I was considering using a subreport, when the user clicks a contract, then i go into the subcontracts, which makes sense because the displayed fields are different for subcontracts. but i prefer the drill-down capability and keeping the user on the same page.

Its possible my SQL is wrong, but is there a way to show this data with a different data set, without having to move to a new report?

because of confidentiality agreements i cant post any code, but i will add a screenshot of what i get now, and dont like. if you notice by  the screenshot, i have a single contract, with multiple subcontracts showing the items that are sold as part of that. I want to show the items but get the dollar amount correct.

also as a subtopic, why dont my parameters go across the whole top bar? is there a way to contorl the order and location of the parameter selection screens?
ssrs-Capture-redacted.jpg
0
Comment
Question by:mikegrad7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:ValentinoV
ID: 39888466
my issue is when i join to the subcontracts table, i get multiple rows in my result per contract, which creates a problem for the contract amount. the contract amount is repeated in each row, and when SSRS subtotals it the numbers are way high.

By default SSRS uses Sum(Fields!YourField.Value)... To avoid summing numbers which don't need to get summed, replace Sum with First.

More info: First Function (Report Builder and SSRS)
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 39888473
also as a subtopic, why dont my parameters go across the whole top bar? is there a way to contorl the order and location of the parameter selection screens?

The only thing that can be controlled is the order.  To change order using BIDS (Visual Studio), open the Report Data window (CTRL + ALT + D), select a parameter and use the blue up/down arrow icons to move it.
0
 
LVL 1

Author Comment

by:mikegrad7
ID: 39889024
Thanks for the comments. The First would work, i think. I just need a way to suppress the values in the detail, which i think i can do with a formula. but if i suppress the value in the cell, will it still give me the first? I'm going to give this a shot now..
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:mikegrad7
ID: 39889204
So i did this and it works when i sum by contract, but when I want to sum up all contracts it  looks at every line. This is a grouping at the salesperson level, and not the contract level. I need a way to just sum the "Firsts" for each subgroup to get this correct. Is this possible?

see the new image. the 13mm is incorrect, but the subtotals are corrct  now. The 13mm is a Sum(AmountGross). Using First(AmountGross) just gives one of the sub group sum values.
SSRS2.PNG
0
 
LVL 37

Accepted Solution

by:
ValentinoV earned 500 total points
ID: 39891117
Ow right, that's indeed an issue.  I usually handle this problem in the query.  Have a look at the following query based on the AdventureWorksDW sample database.  It mimics your issue: a reseller has some order records but also has an annual sales amount.  The annual sales amount would get summed incorrectly without any special tricks.

with SalesData as (
	select DP.EnglishProductName, FRS.SalesAmount, FRS.ResellerKey, FRS.OrderDateKey
		, ROW_NUMBER() over (partition by FRS.ResellerKey order by FRS.OrderDateKey) SalesOrderPerReseller_RN
	from dbo.FactResellerSales FRS
	inner join dbo.DimProduct DP on DP.ProductKey = FRS.ProductKey
)
, ResellerData as (
	select DR.ResellerName, DR.AnnualSales, DR.ResellerKey
	from dbo.DimReseller DR
)
/* reseller data only in first sales order record, based on OrderDateKey */
select SD.EnglishProductName, SD.SalesAmount, SD.OrderDateKey
	, RD.ResellerName, RD.AnnualSales
from SalesData SD
left outer join ResellerData RD on RD.ResellerKey = SD.ResellerKey
	and SD.SalesOrderPerReseller_RN = 1

/* annual reseller sales in each sales order record > SUM issue */
--select *
--from SalesData SD
--inner join ResellerData RD on RD.ResellerKey = SD.ResellerKey

Open in new window

Using that ROW_NUMBER() function I'm creating an increasing number for each sales order record per reseller.  This allows me to use a left outer join with that number equal to 1 so only the first sales order record (based on order date) will get reseller data.

If you apply this method to your situation then the sums on the higher level will be correct.
0
 
LVL 1

Author Closing Comment

by:mikegrad7
ID: 39906999
thanks Valentino! Sorry for the delay in marking it accepted.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Time Corrections for Reports Working with a report, we made some interesting discoveries about the time corrections/updates We are using the following Parameters: Starting Entered Date (Date) formatted as Data type: "Date/Time" Ending Entered …
Hi All, I am here to write a simple article to move SSRS (SQL Server Reporting Services) reports from one server to another. When I have faced the same issue to move reports those were developed by developer on development server and now need to …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question