How to get total of top 10 With TIES sales in SSRS - sql-server

I am taking Top 10 of Sales Volume grouped by Product categories in SSRS 2012. I need the total of these top 10 but it shows the complete total.
For this I have used running value inside group and Written hidden expression below. This absolutely working for top 10 rows and rows less than 10.. In my report searching based on TaxID..So there may be chance of total sum ties..! so that case this condition is failing
Note: This is condition working for top 10 rows and also rows less than 10...but only failing rows more than 10 rows means top sales ties.( If 10th and 11th category sales are same those are pulling up into report..but sum is making problem for me)
=IIf(RunningValue(Fields!grp.Value, CountDistinct, Nothing) = 10
or (RunningValue(Fields!grp.Value, CountDistinct, Nothing) = CountDistinct(Fields!grp.Value, "DataSet1") and CountDistinct(Fields!grp.Value, "DataSet1") < 10)
, false
, true)
I can't do it on dataset level as I need the complete dataset for other parts in the report. Thanks in advance.

Related

Qlikview Pivot Table Top X by week

I have a pivot table with week number (columns) versus product (rows). I want to see the top 10 products, based on sales, per week, a value of 1 would indicate the product is in the top 10. I'm using the expression below and I'm getting the Top 10 sales over all weeks. How do I get a weekly top 10 (each column would have ten values)?
=if(Aggr(Rank(sum([SALES])),PRODUCT)< 11,1,0)
I would say you are almost there, but you need to add another parameter to the Aggr function (like you've said you want the rank by Product and Week, and currently you are only taking Product into account).
Without knowing the details of your model, the expression would be something like :
=if(Aggr(Rank(sum([SALES])),PRODUCT,WEEK)< 11,1,0)

Matching patterns based on query result in SQL

I have a SQL query which returns three columns Contact Id's, No of participations, Year of participation.
Based on this query result, I need to look for the pattern if anyone attended for certain (same number every year) number of times over the years.
For example, 2 times every year or 3 times every year for 2 years or more consecutively (and not different number of times in each year).
From the sample below, contacts I would be interested to be pulling are 1008637, 1009256, 1010306 & 1011263
Please let me know how to achieve this.
Please see image for sample data.
You would need an aggregation twice. Once to get the number of participations and then to check the number condition for each year.
select id
from (select id,year,count(*) as num_participations
from tbl
group by id,year
) t
group by id
having count(*) = count(distinct case when num_participations = 2 then year end)

Load time variance with .CacheSize/.PageSize in ADODB.Recordset

I am working on a project for a client using a classic ASP application I am very familiar with, but in his environment is performing more slowly than I have ever seen in a wide variety of other environments. I'm on it with many solutions; however, the sluggishness has got me to look at something I've never had to look at before -- it's more of an "acadmic" question.
I am curious to understand a category page with say 1800 product records takes ~3 times as long to load as a category page with say 54 when both are set to display 50 products per page. That is, when the number of items to loop through is the same, why does the variance in the total number of records make a difference in loading the number of products displayed when that is a constant?
Here are the methods used, abstracted to the essential aspects:
SELECT {tableA.fields} FROM tableA, tableB WHERE tableA.key = tableB.key AND {other refining criteria};
set rs=Server.CreateObject("ADODB.Recordset")
rs.CacheSize=iPageSize
rs.PageSize=iPageSize
pcv_strPageSize=iPageSize
rs.Open query, connObj, adOpenStatic, adLockReadOnly, adCmdText
dim iPageCount, pcv_intProductCount
iPageCount=rs.PageCount
If Cint(iPageCurrent) > Cint(iPageCount) Then iPageCurrent=Cint(iPageCount)
If Cint(iPageCurrent) < 1 Then iPageCurrent=1
if NOT rs.eof then
rs.AbsolutePage=Cint(iPageCurrent)
pcArray_Products = rs.getRows()
pcv_intProductCount = UBound(pcArray_Products,2)+1
end if
set rs = nothing
tCnt=Cint(0)
do while (tCnt < pcv_intProductCount) and (count < pcv_strPageSize)
{display stuff}
count=count + 1
loop
The record set is converted to an array via getRows() and the destroyed; records displayed will always be iPageSize or less.
Here's the big question:
Why, on the initial page load for the larger record set (~1800 records) does it take significantly longer to loop through the page size (say 50 records) than on the smaller records set (~54 records)? It's running through 0 to 49 either way, but takes a lot longer to do that the larger the initial record set/getRows() array is. That is, why would it take longer to loop through the first 50 records when the initial record set/getRows() array is larger when it's still looping through the same number of records/rows before exiting the loop?
Running MS SQL Server 2008 R2 Web edition
You are not actually limiting the number of records returned. It will take longer to load 36 times more records. You should change your query to limit the records directly rather than retrieving all of them and terminating your loop after the first 50.
Try this:
SELECT *
FROM
(SELECT *, ROW_NUMBER() OVER(ORDER BY tableA.Key) AS RowNum
FROM tableA
INNER JOIN tableB
ON tableA.key = tableB.key
WHERE {other refining criteria}) AS ResultSet
WHERE RowNum BETWEEN 1 AND 50
Also make sure the columns you are using to join are indexed.

SQL Server Reporting

I have a Matrix style report that I have created and it is currently displaying a total count of items for a series of companies throughout a 12 month period.
[Company1] [Company2] [Etc....] [Total]
[May] (Count)(Percent)
[June]
[Etc]
[Totals]-----------------------------------------------------
The last column total is a subtotal function and automatically adds column counts based on what is in the Column group which in my case gives me a total for both (Count)(Percent)
I only want to show <Count> but I don't find any method of modifying the parameters for the subtotal function.
The only way I found was to add an additional matrix to the right hand side of the main but only display total counts. Kind of hokey and I will refrain from implementing it at this time.
Any suggestions?

SSRS Calculating counts across row and column groups

I'm building a report of case results with a parent-child grouping on the row group and single column grouping:
Parent Row Group: Location
Child Row Group: Result
Column Group: Month
Running across the report are months in the year, and running down the report are the location and the different result breakdowns for the location in the given month. Looks something like this:
Jan Feb Total
% # % # % #
Main Office
Pass ? 5 ? 6 55% 11
Fail ? 5 ? 4 45% 9
Total 10 10 20
Other Office
Pass ? 3 ? 2 25% 5
Fail ? 7 ? 8 75% 15
Total 10 10 20
I have everything working except for the percentage breakdowns as indicated by the question marks above. I can't seem to get that total (the 10 for each month/location set above) reflected into my expression caclulation. Any ideas on how to setup my groups and variables to properly render these percentages?
Here's my attempts so far:
Count(Fields!Result.Value, "dsResults") = 40
Count(Fields!Result.Value, "LocationRowGroup") = 20
Count(Fields!Result.Value, "ResultRowGroup") = 11 - (for the Main Office/January/Pass cell, which is the total for the whole year for that result)
Count(Fields!Result.Value, "MonthColumnGroup") = 20
SSRS gets the count correct on the total line right, so there must be a way to reproduce that scope within the data cells?
I sometimes work around annoying SSRS scope issues by pre-calculating my totals, subtotals and percentages. Take a look at this response (to a different post) for an example. I know it is unsatisfying, but it works: pre-calc values suggestion

Resources