String Cleaning

  • Last update: June 13, 2025
  • Overview

    Expected Effect

    Sometimes, you need to remove unnecessary characters from the data.

    Example: parentheses (enclosing negative numbers), special currency symbols ($), and thousands separators (built-in with numeric values), as shown in the following figure.

    1.1.png

    Implementation Method

    First, use the LEFT() function to extract the first character of the field and compare it with the left parenthesis to determine whether a number is positive or negative.

    Second, use the REPLACE() function to replace unnecessary characters in the field, including parentheses, currency symbols, and thousands separators.

    Finally, use the TODOUBLE() function to convert the text-type data to the numeric type.

    Steps

    You can click to download the demo Excel: Order_Profit.xlsx

    If you want to follow the steps described in this document, you can import the demo Excel to the database.

    Importing the Data

    Log in to FineDataLink, enter Data Development, create a scheduled task, and add a Data Transformation node, as shown in the following figure.

    2.1-1.jpg

    Enter the Data Transformation page, and add a DB Table Input operator to import the demo Excel for subsequent data cleaning, as shown in the following image.

    2.1-2.jpg

    Click Data Preview to view the demo Excel, as shown in the following figure.

    2.1-3.jpg

    New Calculation Column

    Enter the field name and input the formula, as shown in the following figure.

    TODOUBLE(if(left(#{Profit},1)="(","-"+REPLACE(REPLACE(REPLACE(REPLACE(#{Profit},"$",""),",",""),"(",""),")",""),REPLACE(REPLACE(#{Profit},"$",""),",","")))

    2.2-1.jpg

    The following table describes the formula:

    FormulaDescription

    REPLACE(Profit,"","")

    Replaces the dollar sign ($) in the Profit field with an empty string.

    REPLACE(REPLACE(REPLACE(Profit,"",""),",",""),

    "(","")

    Replaces the dollar sign ($) in the Profit field with an empty string and removes the left parenthesis.

    REPLACE(REPLACE(REPLACE(REPLACE(Profit,"",""),",",""),"(",""),")","")

    Replaces the dollar sign ($) in the Profit field with an empty string and removes the left and right parentheses.

    REPLACE(REPLACE(Profit,"",""),",","")

    Replaces the dollar sign ($) in the Profit field with an empty string and removes the thousands separator (,).

    if(left(Profit,1)="(","-"+REPLACE(REPLACE(REPLACE(REPLACE(Profit,"$",""),",",""),"(",""),")",""),REPLACE(REPLACE(Profit,"$",""),",",""))

    Removes the left parenthesis and the dollar sign ($) if the second character of the Profit field is the left parenthesis, and prepend a hyphen (-) to the processed field.

    Replaces the dollar sign ($) in the Profit field with an empty string and removes the thousands separator (,) if the second character of the Profit field is not the left parenthesis.

    TODOUBLE()

    Converts the result from the text type to the numeric type

    After completing the above steps, click Data Preview to view the processed field in the Profit_Correction column, as shown in the following figure.

    2.2-2.jpg

    附件列表


    主题: 数据开发
    Previous
    Next
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy