Forum Discussion

ExcelKnut's avatar
ExcelKnut
Frequent Visitor
1 year ago
Solved

Remove trailing commas

If values in a column contain a trailing comma, I need to remove it.  However, commas separating values within that column need to be kept.  I tried using Text.TrimEnd but that didn't work.  

 

Any help is greatly appreciated!!!

 

Jeff

 

 

  • Hi ExcelKnut, what do you mean that Text.TrimEnd didn't work?

     

    Before

    After

    let
        Source = #table(null, {{"Native American,"}, {"Asian, Black,"}}),
        Custom1 = Table.TransformColumns(Source, {{"Column1", each Text.TrimEnd(_, ",")}})
    in
        Custom1

12 Replies

  • ExcelKnut Add a new custom column with the following formula:

    = Text.Replace(Text.TrimEnd([YourColumnName], ","), ",,", ",")

    • ExcelKnut's avatar
      ExcelKnut
      Frequent Visitor

      Thanks for your quick response.  Unfortunately, that didn't seem to solve the issue.  

       

      Formula used:  Text.Replace(Text.TrimEnd([Race], ","), ",,", ",")

       

      Example #1:   Native American,

      Example #2:  Asian, Black,

      • bhanu_gautam's avatar
        bhanu_gautam
        Icon for Super User rankSuper User

        Use this m
        = if Text.EndsWith([YourColumnName], ",") then
        Text.Start([YourColumnName], Text.Length([YourColumnName]) - 1)
        else
        [YourColumnName]

  • Hi ExcelKnut , you could probably give a go at this solution and see if it suits you. I'll leave the code and output below. Thanks

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ExcelKnut,

     

    As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
    If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

     

    Regards,
    Vinay Pabbu

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi ExcelKnut,

       

      May I ask if you have gotten this issue resolved?

      If it is solved, please mark the helpful reply or share your solution and accept it as solution, it will be helpful for other members of the community who have similar problems as yours to solve it faster.

       

      Regards,
      Vinay Pabbu

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi @ExcelKnut,

         

        As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
        If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

         

        Regards,
        Vinay Pabbu

  • dufoq3's avatar
    dufoq3
    Icon for Community Champion rankCommunity Champion

    Hi ExcelKnut, what do you mean that Text.TrimEnd didn't work?

     

    Before

    After

    let
        Source = #table(null, {{"Native American,"}, {"Asian, Black,"}}),
        Custom1 = Table.TransformColumns(Source, {{"Column1", each Text.TrimEnd(_, ",")}})
    in
        Custom1