2016-12-14 21 views
2

我花了很長時間尋找解決方案,並沒有找到我想要的東西。努力適應現有的解決方案,解決不同的問題也沒有奏效!SSRS從Lookupset的最大日期

我使用LookupSet返回日期列表,然後將它們連接到返回一個列表:

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

我想只顯示從該名單上的最近日期。以下是我迄今爲止嘗試:

  • 上述功能包裝在一個最大的功能(不工作,因爲加入返回一個字符串)
  • 使用分割功能分割尋找逗號結果字符串然後使用max函數
  • 做上述兩種但輸出轉換爲使用CDATE和DateTime.Parse第一如下Date對象...

    =加入(LookupSet(領域!cPatSer.Value,菲爾茲! cPatSer.Value,CDate(Fields!DDate.Value),「PatD」))

    =加入(LookupSet(領域!cPatSer.Value,菲爾茲!cPatSer.Value,DateTime.Parse(領域!DDate.Value), 「PATD」))

任何人能提供任何指針嗎?

回答

2

我找到了一個解決方案,使用自定義代碼。 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

+0

道歉花了這麼長時間來回複評論,這是一個巨大的幫助,謝謝! –