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

Time:02-12

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]

CodePudding user response:

Try

add column .. custom column ...

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

or

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

CodePudding user response:

You could also try

Text.AfterDelimiter([Column1], [Column2])

as long as [Column2] isn't blank.

You can use try ... otherwise to cover that situation.

try Text.AfterDelimiter([Column1], [Column2]) otherwise ""
  • Related