SSRS Report Design Question - drill down / sub report

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
LVL 1
mikegrad7Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ValentinoVBI ConsultantCommented:
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
ValentinoVBI ConsultantCommented:
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
mikegrad7Author Commented:
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
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

mikegrad7Author Commented:
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
ValentinoVBI ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mikegrad7Author Commented:
thanks Valentino! Sorry for the delay in marking it accepted.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SSRS

From novice to tech pro — start learning today.