【问题标题】:SSRS Max date from Lookupset来自 Lookupset 的 SSRS 最大日期
【发布时间】:2017-04-29 18:44:34
【问题描述】:

我花了很长时间四处寻找解决方案,但没有找到我想要的。为不同问题调整现有解决方案的努力也没有奏效!

我正在使用 LookupSet 返回日期列表,然后加入它们以返回列表:

=Join(LookupSet(Fields!cPatSer.Value,Fields!cPatSer.Value,Fields!DDate.Value,"PatD"))

我只想显示该列表中最近的日期。到目前为止,这是我尝试过的:

  • 上面的函数包装在一个 Max 函数中(不起作用,因为 Join 返回一个字符串)
  • 使用拆分函数拆分生成的字符串,查找逗号,然后使用 max 函数
  • 执行上述两项操作,但首先使用 CDate 和 DateTime.Parse 将输出转换为 Date 对象,如下所示...

    =Join(LookupSet(Fields!cPatSer.Value,Fields!cPatSer.Value,CDate(Fields!DDate.Value),"PatD"))

    =Join(LookupSet(Fields!cPatSer.Value,Fields!cPatSer.Value,DateTime.Parse(Fields!DDate.Value),"PatD"))

谁能指点一下?

【问题讨论】:

    标签: date reporting-services ssrs-2008 max


    【解决方案1】:

    我找到了使用自定义代码的解决方案。 Oz Locke 做了一个函数,可以对整数数据进行各种聚合(下面的链接),我已经修改了这个函数来代替日期。

    在报告的Code 属性中,粘贴以下内容:

    'Amended from Oz Locke's code:
    'https://github.com/OzLocke/SSRSAggLookup/blob/master/AggLookup.vb
    'Allows users to adjust the aggregation type of lookupsets in a cell
    Function AggLookup(ByVal choice As String, ByVal items As Object)
    
    'Ensure passed array is not empty
    'Return a zero so you don't have to allow for Nothing
    If items Is Nothing Then
        Return 0
    End If
    
    'Define names and data types for all variables
    Dim current As Date
    Dim count As Integer
    Dim min As Date
    Dim max As Date
    Dim err As String
    
    'Define values for variables where required
    current = CDate("01/01/1900")
    count = 0
    err = ""
    
    'Calculate and set variable values
    For Each item As Object In items
    
        'Calculate Count
        count += 1
    
        'Check value is a number
        If IsDate(item) Then
    
            'Set current
            current = CDate(item)
    
            'Calculate Min
            If min = Nothing Then
                min = current
            End If
            If min > current Then
                min = current
            End If
    
            'Calculate the Max
            If max = Nothing Then
                max = current
            End If
            If max < current Then
                max = current
            End If
    
            'If value is not a number return "NaN"
        Else
            err = "NaN"
        End If
    
    Next
    
    'Select and set output based on user choice or parameter one
    If err = "NaN" Then
        If choice = "count" Then
            Return count
        Else
            Return 0
        End If
    Else
        Select Case choice
            Case "count"
                Return count
            Case "min"
                Return min
            Case "max"
                Return max
        End Select
    End If
    End Function
    

    然后在报告的单元格中,使用以下表达式:

    =code.AggLookup("max", LookupSet(Fields!cPatSer.Value,Fields!cPatSer.Value,Fields!DDate.Value,"PatD"))
    

    https://itsalocke.com/aggregate-on-a-lookup-in-ssrs/ https://github.com/OzLocke/SSRSAggLookup/blob/master/AggLookup.vb

    【讨论】:

    • 很抱歉花了这么长时间才回复评论,这是一个巨大的帮助,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多