如何在 SSRS 报告中的串联字符串数组上形成范围
How to form a range on a concatenated string array in SSRS report
数据在 SQL 数据库中的不同行中。它已经被分组,然后连接起来得到这种格式的 table 。但是,我需要为到期值形成一个范围。
我尝试了一些想法,例如:
=IIF(字段!Pivot_2.Value.Contains(“年”),“30 年”,无)
并在数据集属性中使用计算字段,例如:
=拆分(字段!Pivot_2.Value,",")(0)
但是不确定如何扩展它以获得此单元格的范围。
期望的输出:抓住年中最大的和天中最小的。如果天数不存在,则数月内最小。大约 30 年 - 1 天。
您可以使用以下自定义代码
Public Function ParsePeriods(ByVal str As String) As String
Dim iMin As Integer = 1000000
Dim iMax As Integer = -1
Dim sMin As String = ""
Dim sMax As String = ""
' Replace text with numbers to make it comparable
str = Replace(str, " years", "0000")
str = Replace(str, " year", "0000")
str = Replace(str, " months", "00")
str = Replace(str, " month", "00")
str = Replace(str, " days", "")
str = Replace(str, " day", "")
' Split string elements and loop to get the min and max values
Dim strArr() As String = str.Split(",")
For Each element As String In strArr
If Cint(element) < iMin Then
iMin = Cint(element)
End If
If Cint(element) > iMax Then
iMax = Cint(element)
End If
Next
' Use the integer min and max values to create min and max strings
If iMin < 100 Then
sMin = Cstr(iMin) & " day(s)"
ElseIf iMin < 10000
sMin = Cstr(iMin/100) & " month(s)"
Else
sMin = Cstr(iMin/10000) & " year(s)"
End If
If iMax < 100 Then
sMax = Cstr(iMax) & " day(s)"
ElseIf iMax < 10000
sMax = Cstr(iMax/100) & " month(s)"
Else
sMax = Cstr(iMax/10000) & " year(s)"
End If
Return Cstr(sMin) & " - " & Cstr(sMax)
End Function
现在您可以使用如下表达式调用自定义代码
= Code.ParsePeriods( ReportItems!MaturityValue.Value )
更新
您可以对 SP 评级应用类似的逻辑
Public Function ParseSPrating(ByVal str As String) As String
Dim sMin As String = "111111111"
Dim sMax As String = "-1"
str = Replace(str, " ", "")
str = Replace(str, "A", "9")
str = Replace(str, "B", "8")
str = Replace(str, "C", "7")
str = Replace(str, "D", "6")
str = Replace(str, "+", "2")
str = Replace(str, "-", "0")
Dim strArr() As String = str.Split(",")
For Each element As String In strArr
If Cint( Left(element & "1111",4) ) < CInt(sMin) Then
sMin = Left(element & "1111",4)
End If
If Cint( Left(element & "1111",4) ) > CInt(sMax) Then
sMax = Left(element & "1111",4)
End If
Next
sMin = Replace(sMin, "9", "A")
sMin = Replace(sMin, "8", "B")
sMin = Replace(sMin, "7", "C")
sMin = Replace(sMin, "6", "D")
sMin = Replace(sMin, "2", "+")
sMin = Replace(sMin, "0", "-")
sMin = Replace(sMin, "1", "")
sMax = Replace(sMax, "9", "A")
sMax = Replace(sMax, "8", "B")
sMax = Replace(sMax, "7", "C")
sMax = Replace(sMax, "6", "D")
sMax = Replace(sMax, "2", "+")
sMax = Replace(sMax, "0", "-")
sMax = Replace(sMax, "1", "")
Return sMax & " - " & sMin
End Function
数据在 SQL 数据库中的不同行中。它已经被分组,然后连接起来得到这种格式的 table 。但是,我需要为到期值形成一个范围。
我尝试了一些想法,例如: =IIF(字段!Pivot_2.Value.Contains(“年”),“30 年”,无)
并在数据集属性中使用计算字段,例如: =拆分(字段!Pivot_2.Value,",")(0)
但是不确定如何扩展它以获得此单元格的范围。
期望的输出:抓住年中最大的和天中最小的。如果天数不存在,则数月内最小。大约 30 年 - 1 天。
您可以使用以下自定义代码
Public Function ParsePeriods(ByVal str As String) As String
Dim iMin As Integer = 1000000
Dim iMax As Integer = -1
Dim sMin As String = ""
Dim sMax As String = ""
' Replace text with numbers to make it comparable
str = Replace(str, " years", "0000")
str = Replace(str, " year", "0000")
str = Replace(str, " months", "00")
str = Replace(str, " month", "00")
str = Replace(str, " days", "")
str = Replace(str, " day", "")
' Split string elements and loop to get the min and max values
Dim strArr() As String = str.Split(",")
For Each element As String In strArr
If Cint(element) < iMin Then
iMin = Cint(element)
End If
If Cint(element) > iMax Then
iMax = Cint(element)
End If
Next
' Use the integer min and max values to create min and max strings
If iMin < 100 Then
sMin = Cstr(iMin) & " day(s)"
ElseIf iMin < 10000
sMin = Cstr(iMin/100) & " month(s)"
Else
sMin = Cstr(iMin/10000) & " year(s)"
End If
If iMax < 100 Then
sMax = Cstr(iMax) & " day(s)"
ElseIf iMax < 10000
sMax = Cstr(iMax/100) & " month(s)"
Else
sMax = Cstr(iMax/10000) & " year(s)"
End If
Return Cstr(sMin) & " - " & Cstr(sMax)
End Function
现在您可以使用如下表达式调用自定义代码
= Code.ParsePeriods( ReportItems!MaturityValue.Value )
更新
您可以对 SP 评级应用类似的逻辑
Public Function ParseSPrating(ByVal str As String) As String
Dim sMin As String = "111111111"
Dim sMax As String = "-1"
str = Replace(str, " ", "")
str = Replace(str, "A", "9")
str = Replace(str, "B", "8")
str = Replace(str, "C", "7")
str = Replace(str, "D", "6")
str = Replace(str, "+", "2")
str = Replace(str, "-", "0")
Dim strArr() As String = str.Split(",")
For Each element As String In strArr
If Cint( Left(element & "1111",4) ) < CInt(sMin) Then
sMin = Left(element & "1111",4)
End If
If Cint( Left(element & "1111",4) ) > CInt(sMax) Then
sMax = Left(element & "1111",4)
End If
Next
sMin = Replace(sMin, "9", "A")
sMin = Replace(sMin, "8", "B")
sMin = Replace(sMin, "7", "C")
sMin = Replace(sMin, "6", "D")
sMin = Replace(sMin, "2", "+")
sMin = Replace(sMin, "0", "-")
sMin = Replace(sMin, "1", "")
sMax = Replace(sMax, "9", "A")
sMax = Replace(sMax, "8", "B")
sMax = Replace(sMax, "7", "C")
sMax = Replace(sMax, "6", "D")
sMax = Replace(sMax, "2", "+")
sMax = Replace(sMax, "0", "-")
sMax = Replace(sMax, "1", "")
Return sMax & " - " & sMin
End Function