Forum Discussion

Kenn's avatar
Kenn
New Contributor
3 days ago

Removing Duplicates from a Member Filter

Hi All, 

I have the following use case whereby in my parameter, I have a member list of C#Local,C#USD,C#JPY,C#|WFText2| whereby WFText2 will be currencies/consolidation members eg. CNY,EUR,SGD,USD,JPY

Is there a way to filter the member list to remove duplicates such that if WFText2 is USD, the memberlist will return C#Local,C#USD,C#JPY instead of C#Local,C#USD,C#JPY,C#USD

Any help is appreciated, thanks! 

2 Replies

  • sameburn's avatar
    sameburn
    Icon for OneStream Employee rankOneStream Employee

    Hi Kenn​

    If you are working with a Member List you can use something like this Linq syntax (see vb example below).

    ** This assumes that we are using object Member in our list and therefore we can access Name property

    Dim List(of Member) distinctByName = yourMemberList _
        .GroupBy(Function(p) p.Name) _
        .Select(Function(g) g.First()) _
        .ToList()

    This will get the First instance of duplicate e.g C#Local in your example. If you want Last, simply change syntax to be .Last() instead 

    Hope this helps

    Sam

  • MarcusH's avatar
    MarcusH
    Valued Contributor

    I am assuming that when you say 'member list' you mean a text string that contains a list of members rather than an object which is List(Of Member). You can use a hashset for that like this:

    Dim input As String = "C#Local,C#USD,C#JPY,C#USD"
    ' Split the string by commas
    Dim members() As String = input.Split(","c)  
    
    ' Use a HashSet to filter unique members efficiently
    Dim uniqueMembers As New HashSet(Of String)(members)
    
    ' Join back the unique members into a string
    Dim result As String = String.Join(",", uniqueMembers)