Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

extract only number value in query

Hi,

Values is mixed up with number and text.

Need only number so output will be:

 

16571

10000

0

0

0

0

0

0

41429

0

 

 

  • Hello Anonymous,

    Thanks for your follow-up and clarification regarding the "金額" column.

    Based on your updated query, you can modify your code to extract only the numeric values from the "金額" column like this:

    let
    
        // Existing steps
    
        #"Renamed Columns2" = Table.RenameColumns(#"Expanded Work Order PDF - bottom", {
    
            {"Work Order PDF - top b.派工單號", "派工單號"},
    
            {"Work Order PDF - top b.PO NO", "PO NO"},
    
            {"Work Order PDF - middle.標的物編號", "標的物編號"},
    
            {"Work Order PDF - middle.標的物名稱", "標的物名稱"},
    
            {"Work Order PDF - middle.監工人員", "監工人員"},
    
            {"Work Order PDF - middle.備 註", "備 註"},
    
            {"Work Order PDF - bottom.派工工程項目", "派工工程項目"},
    
            {"Work Order PDF - bottom.4G or 5G", "4G or 5G"},
    
            {"Work Order PDF - bottom.安裝型態", "安裝型態"},
    
            {"Work Order PDF - bottom.金額", "金額"},
    
            {"Work Order PDF - bottom.數量", "數量"}
    
        }),
    
       
    
        #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns2", {
    
            "Source Name", "通知日期", "派工目的", "派工單號", "PO NO",
    
            "標的物編號", "標的物名稱", "監工人員", "備 註", "派工工程項目",
    
            "4G or 5G", "安裝型態", "金額", "數量", "Date created"
    
        }),
    
    
    
        // New step: Remove non-numeric characters from 金額 column
    
        #"RemoveNonNumericFrom金額" = Table.TransformColumns(#"Reordered Columns", {
    
            {"金額", each Text.Select(Text.From(_), {"0".."9"}), type text}
    
        }),
    
    
    
        // New step: Convert cleaned 金額 column to number
    
        #"金額ToNumber" = Table.TransformColumnTypes(#"RemoveNonNumericFrom金額", {
    
            {"金額", Int64.Type}
    
        })
    
    in
    
        #"金額ToNumber"

     

    • We first convert "金額" to text, then keep only digits using Text.Select.
    • Finally, we convert it back to a number type.

    This ensures that if your "金額" column contains mixed text and numbers (e.g., "金額=NTD5000"), it will properly extract only the numbers (e.g., 5000).

     

    If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
    Thank you.

7 Replies

  • Anonymous Add a new custom column by going to the "Add Column" tab and selecting "Custom Column".
    In the Custom Column formula box, enter the following formula to extract only the numeric values:

    = try Number.FromText(Text.Select([YourColumnName], {"0".."9"})) otherwise 0
     
     
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi,

      Code doesn't seem to correct,, should I put 'try' as well?
      If I remove 'try' also not working. shoud I put all number one by one? 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, Anonymous 

    Thanks for the reply from bhanu_gautam. Try this in Power Query.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKs4sSS3Wfdbd9nLmkvinPdN1Dc1MzQ2VYnWilQwNgADMwk+aGJoYWSLxLSH6YgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
        RemoveNonNumeric = Table.TransformColumns(Source, {"Column1", each Text.Select(_, {"0".."9"}), type text}),
        ChangeType = Table.TransformColumnTypes(RemoveNonNumeric,{{"Column1", Int64.Type}})
    in
        ChangeType

     

    Best Regards,
    Yang

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know.
    Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi,

       

      Can you re-write the code pls?

       

      #"Renamed Columns2" = Table.RenameColumns(#"Expanded Work Order PDF - bottom",{{"Work Order PDF - top b.派工單號", "派工單號"}, {"Work Order PDF - top b.PO NO", "PO NO"}, {"Work Order PDF - middle.標的物編號", "標的物編號"}, {"Work Order PDF - middle.標的物名稱", "標的物名稱"}, {"Work Order PDF - middle.監工人員", "監工人員"}, {"Work Order PDF - middle.備 註", "備 註"}, {"Work Order PDF - bottom.派工工程項目", "派工工程項目"}, {"Work Order PDF - bottom.4G or 5G", "4G or 5G"}, {"Work Order PDF - bottom.安裝型態", "安裝型態"}, {"Work Order PDF - bottom.金額", "金額"}, {"Work Order PDF - bottom.數量", "數量"}}),
      #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns2",{"Source Name", "通知日期", "派工目的", "派工單號", "PO NO", "標的物編號", "標的物名稱", "監工人員", "備 註", "派工工程項目", "4G or 5G", "安裝型態", "金額", "數量", "Date created"})
      in
      #"Reordered Columns"

       

       

      "金額" is the column related. 

      • v-ssriganesh's avatar
        v-ssriganesh
        Community Support

        Hello Anonymous,

        Thanks for your follow-up and clarification regarding the "金額" column.

        Based on your updated query, you can modify your code to extract only the numeric values from the "金額" column like this:

        let
        
            // Existing steps
        
            #"Renamed Columns2" = Table.RenameColumns(#"Expanded Work Order PDF - bottom", {
        
                {"Work Order PDF - top b.派工單號", "派工單號"},
        
                {"Work Order PDF - top b.PO NO", "PO NO"},
        
                {"Work Order PDF - middle.標的物編號", "標的物編號"},
        
                {"Work Order PDF - middle.標的物名稱", "標的物名稱"},
        
                {"Work Order PDF - middle.監工人員", "監工人員"},
        
                {"Work Order PDF - middle.備 註", "備 註"},
        
                {"Work Order PDF - bottom.派工工程項目", "派工工程項目"},
        
                {"Work Order PDF - bottom.4G or 5G", "4G or 5G"},
        
                {"Work Order PDF - bottom.安裝型態", "安裝型態"},
        
                {"Work Order PDF - bottom.金額", "金額"},
        
                {"Work Order PDF - bottom.數量", "數量"}
        
            }),
        
           
        
            #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns2", {
        
                "Source Name", "通知日期", "派工目的", "派工單號", "PO NO",
        
                "標的物編號", "標的物名稱", "監工人員", "備 註", "派工工程項目",
        
                "4G or 5G", "安裝型態", "金額", "數量", "Date created"
        
            }),
        
        
        
            // New step: Remove non-numeric characters from 金額 column
        
            #"RemoveNonNumericFrom金額" = Table.TransformColumns(#"Reordered Columns", {
        
                {"金額", each Text.Select(Text.From(_), {"0".."9"}), type text}
        
            }),
        
        
        
            // New step: Convert cleaned 金額 column to number
        
            #"金額ToNumber" = Table.TransformColumnTypes(#"RemoveNonNumericFrom金額", {
        
                {"金額", Int64.Type}
        
            })
        
        in
        
            #"金額ToNumber"

         

        • We first convert "金額" to text, then keep only digits using Text.Select.
        • Finally, we convert it back to a number type.

        This ensures that if your "金額" column contains mixed text and numbers (e.g., "金額=NTD5000"), it will properly extract only the numbers (e.g., 5000).

         

        If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
        Thank you.

  • v-ssriganesh's avatar
    v-ssriganesh
    Community Support

    Hi Anonymous,

    May I ask if you have resolved this issue? If so, please mark it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

    Thank you.

  • v-ssriganesh's avatar
    v-ssriganesh
    Community Support

    Hi Anonymous,
    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
    Thank you.