• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to replace 1 or more periods at end of value

In the attached file, I have some values in column G which has 1 or more periods at the end of the value. I am trying to find a way to delete any periods (no matter how many there are) at the end of each value.

If a period appears in the middle of the value, it should be kept.

Column I has what the final result should look like.

I am trying to come up with a formula that can do this.
 

Attachments

  • Chandoo.org Terminating Periods at End.xlsx
    8.3 KB · Views: 13
This relies upon there being no spaces. It turns all the periods into spaces and then trims the excess spaces. Finally it replaces the in-string periods.

= SUBSTITUTE( TRIM( SUBSTITUTE( fromString, ".", " ") ), " ", "." )
 
upload_2019-2-23_8-13-16.png

Or this one, can allow spacing inside the string as per above picture

In I5, enter formula:

=LEFT(G5,AGGREGATE(14,6,ROW($1:$99)/(MID(G5,ROW($1:$99),1)>="0"),1))

or,

=LEFT(G5,MATCH(2,1/(MID(G5,MMULT(ROW($1:$99),1),1)>="0")))

and copied down

Regards
Bosco
 
Last edited:
… but soon it will look like this!

upload_2019-2-23_9-27-11.png

=LEFT(G5,MAX((MID(G5,SEQUENCE(99),1)>="0" )*SEQUENCE(99)))
 

Attachments

  • insiderFast.xlsx
    15.8 KB · Views: 8
This relies upon there being no spaces. It turns all the periods into spaces and then trims the excess spaces. Finally it replaces the in-string periods.

= SUBSTITUTE( TRIM( SUBSTITUTE( fromString, ".", " ") ), " ", "." )

This worked. I thought it would work only for 2 periods but it works for more. How does this work for more than 2 periods at the end, since you have the SUBSTITUTE function only twice?
 
Hi
The SUBSTITUTE is set to switch all occurrences each time it is used (no specific instance is set). The first application turns periods→spaces and, once the spaces are trimmed, the second application turns all remaining spaces→periods.
 
A variation that avoids MMULT (a powerful function, but one I can never clearly explain to others)
Code:
=LEFT(G5,MATCH(2,INDEX(1/(MID(G5,ROW($1:$99),1)>="0"),0)))
 
This worked. I thought it would work only for 2 periods but it works for more. How does this work for more than 2 periods at the end, since you have the SUBSTITUTE function only twice?

Because the first (inner) SUBSTITUTE replaces each full stop (period) with a space. This is then trimmed using the TRIM function, so ALL trailing spaces are removed. Then the remaining spaces are replaced with a full stop (period) by the second (outer) SUBSTITUTE.
 
Another way using Power Query, allowing spaces as in Bosco's solution.
Code:
let
  Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
  #"Replace"".""byLineFeed" = Table.ReplaceValue(Source,".","#(cr) ",Replacer.ReplaceText,{"From"}),
  TrimIt = Table.TransformColumns(#"Replace"".""byLineFeed",{{"From", Text.Trim, type text}}),
  #"ReplaceLineFeedBy"".""" = Table.ReplaceValue(TrimIt,"#(cr)",".",Replacer.ReplaceText,{"From"}),
  RenameFrom_To = Table.RenameColumns(#"ReplaceLineFeedBy"".""",{{"From", "To"}})
in
  RenameFrom_To
 
Back
Top