SSRS 2016 find 2nd minimum/ 2nd maximum

血红的双手。 提交于 2019-12-11 12:15:29

问题


I want to find the second minimum number in my row. I can complete Min and Max by the inbuilt expression.

More information about the SSRS, it is loaded from SSAS datasource.

In the SSRS design, I have followed Chris steps

1.) Put the custom code in to report properties

2.) Input the expression into two separate columns (setMinMaxReset and setMinMax): =Code.setMinMaxReset(Fields!ID_AverageChangeRevenue_Value.Value) =Code.setMinMax(Fields!ID_AverageChangeRevenue_Value.Value)

SSRS design

3.) The =code.min2 was also input into the column MIN2

same for MAX2

but it turn out the result is incorrect. Thank you for your help

SSRS Review


回答1:


You can use custom code in your report to store min2 and max2 in variables (to avoid confusion with multiple get/set functions I declared variables as public)

Public Dim max1 As Integer
Public Dim max2 As Integer
Public Dim min1 As Integer
Public Dim min2 As Integer

Public Function setMinMax(ByVal v As Integer)  As Integer

If max1=0 Then
max1 = v
ElseIf v>max1 Then
max2 = max1
max1 = v
ElseIf v<max1 And v>max2 Then
max2 = v
End If

If min1 = 0 Then
min1 = v
ElseIf v < min1 Then
min2 = min1
min1 = v
Elseif min2=0
min2 = v
ElseIf v<min2
min2 = v
End If

Return v

End Function


Public Function resetMinMax(ByVal s As String) As String 
    max1 = 0
    max2 = 0
    min1 = 0
    min2 = 0

Return s

End Function

For each row group(green color) you will use resetMinMax passing the group string as a parameter. The function will initialize the values for each group row and display the group name

=Code.resetMinMax(Fields!r.Value)

For each value cell (blue color) you will use the setMinMax passing the value as parameter. The function will do the min/max calculations and display the parameter value

=Code.setMinMax(Sum(Fields!v.Value))

For min & max values just call each variable

= Code.max1
= Code.max2
= Code.min1
= Code.min2



来源:https://stackoverflow.com/questions/51034222/ssrs-2016-find-2nd-minimum-2nd-maximum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!