Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Analysis Server and Reporting Services (2008)
 select different dataset based on parameter select

Author  Topic 

HenryFulmer
Posting Yak Master

110 Posts

Posted - 2012-04-26 : 17:48:52
I have a fairly simple report that show my current month sales, margin and inventory value.
I have two datasets:
1 ds to summarize the data by supplier and 1 ds to summarize the data by brand.
The user wants to run the report based on their selection of either supplier or brand.
How would I populate the result table with data from the respective result set depending on if the users sets the supplier parameter or the brand parameter?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-26 : 21:08:28
why do you need two datasets?why not bring the data in detail and do dynamic grouping in report based on parameter selection?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

HenryFulmer
Posting Yak Master

110 Posts

Posted - 2012-04-27 : 10:26:40
If I bring in all the sales details I'm not sure how to reconcile that with my in stock data. My sales details are stored per sales line so I have many entries for the same article number, whereas my in stock data is stored with one entry per article number.
Here's the query I use to get the consolidated results by brand:


SELECT
c.Brand
, a.[MTDSales]
, a.[MTDCost]
, a.[MTDMargin]
, SUM(fis.InStockValue)
FROM FactStockTable b
INNER JOIN dimArticle c ON b.ArtNo = c.ArtNo
INNER JOIN
(SELECT c.Brand, CAST(SUM(d.LineAmount) AS decimal(10, 0)) AS [MTDSales], CAST(SUM(d.Cost) AS decimal(10, 0)) AS [MTDCost],
1 - SUM(d.Cost) / NULLIF (SUM(d.LineAmount), 0) AS [MTDMargin]
FROM FactSalesTable d
INNER JOIN dimArticle AS i ON d.ArtNo = c.ArtNo
INNER JOIN dimDates AS d ON d.SalesDate = d.DateID
INNER JOIN (SELECT CONVERT(CHAR(7), DATEADD(mm, 0, DATEADD(mm, 0, GETDATE())), 120) AS timeframe) AS t ON d.YrMth = t.timeframe
GROUP BY c.Brand) a
ON c.Brand = a.Brand
WHERE c.Brand = @BrandName
GROUP BY c.Brand , a.[MTDSales], a.[MTDCost], a.[MTDMargin]


My query to get the data by supplier looks almost identical, substituting brand with supplier. Am I not approaching this correctly?
Thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-27 : 15:51:47
ok. in that case bring it group by brand as well as supplier separately and merge it using union all to form common dataset of report. Add an additional field called GroupedBy in union all resultset and give it appropriate values (Brand and Supplier) then in report use this field to filter against parameter and get only required level data

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

HenryFulmer
Posting Yak Master

110 Posts

Posted - 2012-05-22 : 13:21:36
Thanks - the unionall works fine and I have now one combined result set. I have created two separate data sets, one for Brand and one for Supplier, to provide available values for the parameters that the user can select from.
I've set up the parameter to allow NULL values and I've et up the default value to be NULL.
I've adjusted my queries to:
WHERE c.Brand  = ISNULL(@BrandName,NULL)

and respectively
WHERE c.Supplier= ISNULL(@SupplierName,NULL)

However, when previewing the report I am always prompted to select values for both parameters. What would need to be changed for the report to accept the NULL value? Thanks for any help.
Go to Top of Page

HenryFulmer
Posting Yak Master

110 Posts

Posted - 2012-05-29 : 13:51:31
I still haven't been able to figure this out on my own. Anybody can provide additional advice?
Thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-29 : 15:07:40
quote:
Originally posted by HenryFulmer

Thanks - the unionall works fine and I have now one combined result set. I have created two separate data sets, one for Brand and one for Supplier, to provide available values for the parameters that the user can select from.
I've set up the parameter to allow NULL values and I've et up the default value to be NULL.
I've adjusted my queries to:
WHERE c.Brand  = ISNULL(@BrandName,NULL)

and respectively
WHERE c.Supplier= ISNULL(@SupplierName,NULL)

However, when previewing the report I am always prompted to select values for both parameters. What would need to be changed for the report to accept the NULL value? Thanks for any help.


your where clauses doesnt make sense

i think it should be
WHERE c.Brand = ISNULL(@BrandName,c.Brand)
etc

also for report not to prompt select allow null value property to true for required parameters in parameter properties

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -