Forum Discussion

pbiforum123's avatar
pbiforum123
Post Patron
4 years ago
Solved

Help needed in creating calculated column and create the values based on the tag using CONTAINSTRING

Fowmy 
I need help in creating the calculated column using CONTAINSTRING or anyother string function.

Let say there is column called "Page Name" in that I need to find the below patterns and tag it as the one given on the right side.


US:*:shop-all:* --> PLP
US:*:products:* --> PDP
US:* --> Homepage
US:search --> SRP

Remaining values tag it as "Others"...

Can you please help on this.Please let me know if you have any questions.

  • tamerj1's avatar
    tamerj1
    3 years ago

    pbiforum123 

    Use

    new column =
    SWITCH (
        TRUE (),
        CONTAINSSTRING ( TableName[ColumnName], "US:*:shop-all:" ), "PLP",
        CONTAINSSTRING ( TableName[ColumnName], "US:*:products:" ), "PDP",
        CONTAINSSTRING ( TableName[ColumnName], "US:search :" ), "SRP",
        CONTAINSSTRING ( TableName[ColumnName], "US:" ), "Homepage",
        "Others"
    )

5 Replies

    • pbiforum123's avatar
      pbiforum123
      Post Patron

      amitchandak Thanks but when I am trying to use the code that you have shared I am getting below error

       

      Function 'SWITCH' does not support comparing values of type True/False with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi pbiforum123 
    Please try

    new column =
    SWITCH (
        TRUE (),
        CONTAINSSTRING ( TableName[ColumnName], "US:*:shop-all:" ), "PLP",
        CONTAINSSTRING ( TableName[ColumnName], "US:*:products:" ), "PDP",
        CONTAINSSTRING ( TableName[ColumnName], "US:search :" ), "SRP",
        CONTAINSSTRING ( TableName[ColumnName], "US:" ), "Homepage"
    )
      • tamerj1's avatar
        tamerj1
        Community Champion

        pbiforum123 

        Use

        new column =
        SWITCH (
            TRUE (),
            CONTAINSSTRING ( TableName[ColumnName], "US:*:shop-all:" ), "PLP",
            CONTAINSSTRING ( TableName[ColumnName], "US:*:products:" ), "PDP",
            CONTAINSSTRING ( TableName[ColumnName], "US:search :" ), "SRP",
            CONTAINSSTRING ( TableName[ColumnName], "US:" ), "Homepage",
            "Others"
        )