2012-01-31 48 views
1

我正在使用SSRS 2008 R2在我的項目中完成一些報告,在我的一份報告中,我想顯示登錄持續時間的中位數以及平均總數等。並且用戶按地區和國家分組,我希望該組的中位數。如何計算SSRS 2008 R2中某個組的中位數

我曾嘗試以下鏈接

http://blogs.msdn.com/b/robertbruckner/archive/2008/07/20/using-group-variables-in-reporting-services-2008-for-custom-aggregation.aspx

但在使用本所以所有的中位數是同樣在這裏,我只得到不分組項目整個登錄時間的中位數。對於不同地區或國家的不同羣體而言應該是不同的。

+0

你嘗試在這裏找到了方法,[在SSRS一組計算中位數(HTTP:/ /techfilth.blogspot.com/2008/07/calculate-median-on-group-in-ssrs.html)? – Homer 2012-08-08 16:06:03

+0

我想我剛剛問過類似的問題。 http://stackoverflow.com/questions/29947709/ssrs-median-by-group-jagged-array?noredirect=1#comment48016553_29947709 – tcarper 2015-04-29 15:17:23

回答

0

我有同樣的問題,問題是隻能在一組數據上使用vbCode,因爲有一個全局共享變量「values」。 爲了解決這個問題,我用下面的查詢報表裏面的每個

中位數:

Select Median.*, (Convert (decimal, Median.bh) + Convert(decimal, Median.th))/2 as MedainResult 

from(
    sELECT 
    (SELECT max(finalGrade) 
     from 
     (SELECT  top 50 percent finalGrade 
     FROM GradeTable 
     WHERE (TermCode = 201410) (CRN = 11735) 
     order by finalGrade) as BottomHalf) as bh 
, 
    (select min(finalGrade) 
    from 
    (SELECT top 50 percent finalGrade 
    FROM GradeTable 
    WHERE (TermCode = 201410) (CRN = 11735) 
    order by finalGrade desc 
    ) as TopHalf 
) as th 
) as Median