SSRS不同的lookupset函数

时间:2014-11-20 19:03:43

标签: reporting-services ssrs-2008-r2 ssrs-grouping

我使用Join(Lookupset)查找返回序列号的唯一组值。这是我的功能:

Join(LookupSet(Fields!itemId.Value & Fields!UseByDate.Value & Fields!rackId.Value
    , Fields!itemId.Value & Fields!UseByDate.Value & Fields!rackId.Value
    , Fields!CustomerSeqNo.Value
    , "PickingList"), ",")

问题在于某些项目有多个交易。我想删除重复项。

我找到了一个博客http://blogs.msdn.com/b/bobmeyers/archive/2012/06/18/creating-short-lists-using-the-lookupset-function.aspx,但无法让SSRS Report Builder参考Linq程序集。我的问题是

enter image description here

如何显示唯一值?

4 个答案:

答案 0 :(得分:11)

您不需要Linq,但您仍然需要自定义代码(在BIDS中转到报告 - >报告属性 - >代码)

你可以在这里放一个RemoveDuplicates函数,如下所示:

Public Shared Function RemoveDuplicates(m_Array As Object()) As String()

    System.Array.Sort(m_Array)
    Dim k As Integer = 0
    For i As Integer = 0 To m_Array.Length - 1
        If i > 0 AndAlso m_Array(i).Equals(m_Array(i - 1)) Then
            Continue For
        End If
        m_Array(k) = m_Array(i)
        k += 1
    Next

    Dim unique As [String]() = New [String](k - 1) {}

    System.Array.Copy(m_Array, 0, unique, 0, k)

    Return unique

End Function

在你的加入中使用它:

Join(Code.RemoveDuplicates(LookupSet(...)),",")

答案 1 :(得分:1)

如果你和我一样,你也希望元素按频率排序(降序)。

我为此创建了以下 VisualBasic 代码

Public Shared Function RemoveDuplicates(dataset As Object()) As String()
    Dim unique As New System.Collections.Generic.List(Of String)
    Dim frequency As New System.Collections.Generic.List(Of Integer)
    For i As Integer = 0 To dataset.Length - 1
        Dim index As Integer = -1
        For j As Integer = 0 To unique.Count - 1
            If dataset(i).Equals(unique(j)) Then
                index = j
                Exit For
            End If
        Next
        If index < 0 Then
          unique.Add(dataset(i))
          frequency.Add(1)
        Else
            frequency(index) += 1
        End If
    Next
    Dim uniqueArray As [String]() = unique.ToArray()
    Array.Sort(frequency.ToArray(), uniqueArray)
    Array.Reverse(uniqueArray)
    return uniqueArray
End Function

这是基于其他人的答案,其中 SSRS 表达式如下

Join(Code.RemoveDuplicates(LookupSet(...)),",")

注意:我在大约一个小时内学会了 VisualBasic 来解决这个问题,所以我的算法可能不是最有效的。

答案 2 :(得分:0)

我同意@ user3697615的观点,认为报告代码是最好的。但是,我更喜欢直接将其构建为字符串:

public shared function JoinDistinct(
  dups as object(),
  delimiter as string
) as string

  dim result as string = ""
  system.array.sort(dups)

  for i as integer = 0 to dups.length - 1
    if i <> 0 then result += delimiter
    if i = 0 orElse dups(i) <> dups(i-1) then result += dups(i)
  next i

  return result

end function

这样,我们消除了调用中的一个嵌套函数:

=Code.JoinDistinct(LookupSet(...), ",")

答案 3 :(得分:0)

我喜欢pwilcox的想法,所以我写了这个过滤掉空值和空值的代码。

Public Function JoinDistinct(arr As Object(), delimiter As String) As String

    System.Array.Sort(arr)
    Dim result As String = String.Empty
    Dim lastvalue As String = String.Empty
    For i As Integer = 0 To arr.Length - 1
        If Not arr(i) Is Nothing And arr(i) <> lastvalue And arr(i) <> String.Empty Then
            If result = String.Empty Then
                result = arr(i)
            Else
                result = result + delimiter + arr(i)
            End If
        End If
        lastvalue = arr(i)
    Next
    Return result
End Function

用法:

=Code.JoinDistinct(LookupSet(...), ",")