Search code examples
excelpowerbipowerquerym

Power Q: how to add conditional col and split based on length if another col contains text of same col


In power Q: creating a custom col based on condition: If col A contains text of col b then split col A starting at the position of the length of ColumB

example: col A is MyMothersBasement123 and col B is MyMothersBase col c would = ment123

Somthing along the lines of : if Text.Contains([ColumnA], [ColumnB]) then SplitTextByPositions({length of ColumB}) else [ColumnA]


Solution

  • Try

    add column .. custom column ...

    = try Text.Split([Column1],[Column2]){1} otherwise [Column1]
    

    or

    = try Text.Replace([Column1],[Column2],"") otherwise [Column1]