I wish to split the sexes of animals from sentences shown in the desired column using Text.Contains:
In this slightly unusual case male is contained within female and so all results return male.
How can I Modify this code to achieve this?
Current M Code:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([Column1], "male", Comparer.OrdinalIgnoreCase) then "Male" else null)
in
#"Added Custom"
update:
This is my current solution:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Females", each if Text.Contains([Column1], "Female", Comparer.OrdinalIgnoreCase) then "Female" else null),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Males", each if Text.Contains([Column1], "Male", Comparer.OrdinalIgnoreCase) then "Male" else null),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Sex", each if [Females] = "Female" then "Female" else if [Males] = "Male" then "Male" else null),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom2",{"Column1", "Sex"})
in
#"Removed Other Columns"
However, I don't really like the need for multiple Custom columns and feel there will be a more elegant solution.

