Solved

SSRS Report Design Question - drill down / sub report

Posted on 2014-02-25
6
789 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
  • 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hi, I have heard from my friends that it’s not possible to create Label Printing report using SSRS. I am amazed after hearing this words not possible in SSRS. I googled lot and found that it is possible to some of people know about the Report Bui…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now