Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Extracting unique values with a condition

Hi,

 

I have a column with text that looks something like this:

 

Fixed-Fixed-Postpaid-Fixed-OMB-OMB

 

Is there a formula that will return only unique values in between the dashes (-)? 

 

Required: Fixed-Postpaid-Fixed-OMB

 

  • tamerj1's avatar
    tamerj1
    4 years ago

    Hi Anonymous 
    Apologies, I was outside the office when I shared the solution. 

    Yes this is a calculated column but its seems that you have some blank cells. Just modify as follows.

     

    NewColumn =
    VAR String = TableName[ColumnName]
    VAR Items =
        SUBSTITUTE ( String, "-", "|" )
    VAR Length =
        COALESCE ( PATHLENGTH ( Items ), 1 )
    VAR T1 =
        GENERATESERIES ( 1, Length, 1 )
    VAR T2 =
        ADDCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) )
    VAR T3 =
        DISTINCT ( SELECTCOLUMNS ( T2, "@@Item", [@Item] ) )
    RETURN
        CONCATENATEX ( T3, [@@Item], "-", [@@Item], ASC )

     

     

6 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      This is what I need but unfortunately I am unable to use this method as mine is a calculated column

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Anonymous 

    please try

    NewColumn =
    VAR String = TableName[ColumnName]
    VAR Items =
        SUBSTITUTE ( String, "-", "|" )
    VAR Length =
        PATHLENGTH ( Items )
    VAR T1 =
        GENERATESERIES ( 1, Length, 1 )
    VAR T2 =
        ADDCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) )
    VAR T3 =
        DISTINCT ( SELECTCOLUMNS ( T2, "@@Item", [@Item] ) )
    RETURN
        CONCATENATEX ( T3, [@@Item], "-", [@@Item], ASC )
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for this. Can I use this code via "New Column"? I did that and got this error 

      "The arguments in GenerateSeries function cannot be blank"

      • tamerj1's avatar
        tamerj1
        Community Champion

        Hi Anonymous 
        Apologies, I was outside the office when I shared the solution. 

        Yes this is a calculated column but its seems that you have some blank cells. Just modify as follows.

         

        NewColumn =
        VAR String = TableName[ColumnName]
        VAR Items =
            SUBSTITUTE ( String, "-", "|" )
        VAR Length =
            COALESCE ( PATHLENGTH ( Items ), 1 )
        VAR T1 =
            GENERATESERIES ( 1, Length, 1 )
        VAR T2 =
            ADDCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) )
        VAR T3 =
            DISTINCT ( SELECTCOLUMNS ( T2, "@@Item", [@Item] ) )
        RETURN
            CONCATENATEX ( T3, [@@Item], "-", [@@Item], ASC )