Forum Discussion

MitchTrott's avatar
MitchTrott
Frequent Visitor
4 years ago
Solved

Conditional Trimming/replacing values

Hi,   This is a 2 part question. this is a snippet of what i have:   . . 1.1.1.1 1.1.1.1 1.1.1.1. 1.1.1.1.   So my quesiton is this, How can I, firstly, remove the last "." without removin...
  • Waldo35's avatar
    4 years ago
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if 
    Text.EndsWith([Column1], ".") then if Text.Length([Column1]) = 1 then null else Text.Start([Column1], Text.Length([Column1])-1) else [Column1])

     So this is the code i wrote in the advanced editor.

    First it checks if it ends with a  .

    if it does end with a dot it takes the entire string except the last character (unless the string is only 1 in length then just return null).  this is to filter out the loose . (record 1 and 2)

     

    Result

     

    Code in the custom column (not advanced editor)

    if Text.EndsWith([Column1], ".") then if Text.Length([Column1]) = 1 then null else Text.Start([Column1], Text.Length([Column1])-1) else [Column1]