Forum Discussion

jerryr125's avatar
jerryr125
Icon for Helper IV rankHelper IV
1 year ago
Solved

Asssign category based upon text in a field

Hi - I am looking to do the following : (I posted this question before but cannot seem to locate it!)   I would like to assign a category to the master table (Master Table) based upon search crite...
  • jgeddes's avatar
    1 year ago

    You can use Comparer.OrdinalIgnoreCase if you do not want to deal with the case of the values.

    The code below provides an example of this.

        Table.AddColumn(
            #"Changed Type",                            //previous step in the query
            "Category", 
            each 
            let 
                searchString = [Text]                   //set the current row [Text] column into a variable
            in 
                Text.Combine(                           //combines the values of the matching Category column list to a single string with a comma delimiter
                    Table.SelectRows(
                        Table2,                         //select rows in Table 2 that have matching text
                        each 
                        Text.Contains(
                            searchString,               //look in the [Text] column of the current row of Table
                            Record.Field(               
                                _,                      //the current row record in Table2
                                "Search Text"           //column name of the values to search for in Table2
                            ), 
                            Comparer.OrdinalIgnoreCase  //ignores the case of the text during the comparison
                        )
                    )[Category],                        //converts the Category column from the resulting selected rows from Table2 into a list
                    ","
                )
            )