2012中找到计算字段的中位数

2012中找到计算字段的中位数

本文介绍了在SSRS 2012中找到计算字段的中位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开始日期和一个结束日期,并且正在计算以下之间的工作日:

I have a start date and an end date, and am calculating the weekdays in between with the following:

  1. 我创建了一个名为CountWeekDays的计算字段,它等于:Code.getBusinessDaysCount(Fields!date_created.Value,Fields!date_closed.Value)

  1. I created a calcuated field called CountWeekDays, and it equals:Code.getBusinessDaysCount(Fields!date_created.Value,Fields!date_closed.Value)

我可以这样获得平均值:= Avg(Fields!CountWeekDays.Value)

I can get an Average of that like this: =Avg(Fields!CountWeekDays.Value)

但是,我无法以相同的方式获得中位数.如何获得计算出的东西的中位数?

However, I cannot get the Median the same way. How can I get the median number of something that is calculated?

我用来获取工作日计数的代码如下:

The code I am using to get the weekday count is as follows:

Function getBusinessDaysCount(ByVal tFrom As Date, ByVal tTo As Date) As Integer
    Dim tCount As Integer
    Dim tProcessDate As Date = tFrom
    For x as Integer= 1 To DateDiff(DateInterval.Day, tFrom, tTo) + 1
      If Not (tProcessDate.DayOfWeek = DayOfWeek.Saturday Or tProcessDate.DayOfWeek = DayOfWeek.Sunday) Then
        tCount = tCount + 1
      End If
      tProcessDate = DateAdd(DateInterval.Day, 1, tProcessDate)
    Next
    Return tCount
End Function

推荐答案

我找到了中位数的代码"

I found code for median"

'MEDIAN code
'code from http://stackoverflow.com/questions/1943437/mean-median-mode-in-sql-server-reporting-services

Dim values As New System.Collections.Generic.List(Of Integer)
Dim valueCounts As New System.Collections.Generic.Dictionary(Of Integer, Integer)

Function AddValue(newValue As Integer) As Integer
values.Add(newValue)
AddValue = newValue
If Not valueCounts.ContainsKey(newValue) Then
    valueCounts.item(newValue) = 1
Else
    valueCounts.item(newValue) += 1
End If
End Function

Function GetMedian() As Double
Dim count As Integer = values.Count
If count = 0 Then
    Return 0
Else
    values.Sort()
    If count Mod 2 = 1 Then
        Return values(CInt((count / 2) - 0.5))
    Else
        Dim index1 As Integer = count \ 2
        Dim index2 As Integer = index1 - 1

        Dim value1, value2 As Integer
        value1 = values(index1)
        value2 = values(index2)

        Return (value1 + value2) / 2
    End If
End If
End Function

这篇关于在SSRS 2012中找到计算字段的中位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:34