Close Menu
    Trending
    • How AI is turning the Iran conflict into theater
    • Why Your AI Search Evaluation Is Probably Wrong (And How to Fix It)
    • Machine Learning at Scale: Managing More Than One Model in Production
    • Improving AI models’ ability to explain their predictions | MIT News
    • Write C Code Without Learning C: The Magic of PythoC
    • LatentVLA: Latent Reasoning Models for Autonomous Driving
    • Understanding Context and Contextual Retrieval in RAG
    • The AI Bubble Has a Data Science Escape Hatch
    ProfitlyAI
    • Home
    • Latest News
    • AI Technology
    • Latest AI Innovations
    • AI Tools & Technologies
    • Artificial Intelligence
    ProfitlyAI
    Home » Separate Numbers and Text in One Column Using Power Query
    Artificial Intelligence

    Separate Numbers and Text in One Column Using Power Query

    ProfitlyAIBy ProfitlyAIDecember 16, 2025No Comments7 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    This can be a typical case for Self-Service BI with Excel knowledge.

    A couple of days in the past, a shopper requested me the next query:

    I’ve an Excel sheet with numbers and textual content in a single column. I wish to import this sheet into Energy BI and carry out evaluation on the numbers in that column.

    How can I separate the numbers from the textual content in that column?

    Do not forget that I would like the textual content in that column as effectively.

    I had by no means been on this scenario, so I first began utilizing the approach I knew.

    I created a Dummy Excel with the identical downside, which seems like this:

    Determine 1 – Pattern Knowledge in Excel (Determine by the Writer)

    To create a PoC, I first loaded this knowledge into an SQL Server database to see how you can clear up it there.

    Fixing the issue by utilizing SQL

    T-SQL has two features which are useful in such situations:

    • TRY_CONVERT()
      • This one tries to transform a worth to a goal knowledge sort. If it fails, it returns NULL.
    • ISNUMERIC()
      • Checks if a worth is a numeric worth. If sure, it returns 1. In any other case, 0.

    Primarily based on this data, I wrote a question to separate the values into two columns. One with the numbers and one with the textual content:

    SELECT [Values]
    
                ,TRY_CONVERT(decimal(18, 5), [Values])         AS    [Number]
    
                ,IIF(ISNUMERIC([Values]) = 0, [Values], NULL) AS    [Text]
    
      FROM [dbo].[MixedValues];

    The result’s the next desk:

    Determine 2 – T-SQL Question to separate the numbers from the textual content (Determine by the Writer)

    When you look rigorously, you see that row 17 is acknowledged as a textual content.

    It’s because the quantity incorporates a clean.

    I’ll come again to this in a while.

    Switching to Energy Question – Making an attempt IsNaN()

    Now, I loaded the Excel into Energy Question.

    I outlined the column as Textual content and began engaged on this problem.

    The primary try makes use of the Number.IsNaN() perform.

    This perform returns true if the worth is NaN.  “NaN” is a placeholder for not relevant, for instance, due to a division by 0.

    I attempted this to find out whether or not a textual content is equal to NaN.

    That is the M-Code for the calculated column:

    if Quantity.IsNaN([Value]) = true
    then [Value]
    else null

    The outcome stunned me:

    Determine 3 – End result with Quantity.IsNaN(). Why doesn’t this perform acknowledge numbers? (Determine by the Writer)

    Unusually, the result’s that it can’t convert a quantity to a quantity.

    I suppose this occurs as a result of the column’s knowledge sort is textual content.

    Then, I attempted changing the column to a quantity and making use of the IsNaN() perform to the outcome:

    if Quantity.IsNaN(Quantity.From([Value])) = false
    then Quantity.From([Value])
    else null

    Now, the numbers are transformed to numbers, however the textual content values lead to an error:

    Determine 4 – Making use of IsNaN() to the transformed values returns the numbers, however an error for the textual content (Determine by the Writer)

    Now the logic works for numbers.

    However the conversion fails for the rows containing textual content. This ends in rows with errors.

    Making an attempt Worth.Is() in Energy Question

    Let’s attempt one other perform: Value.Is()

    This perform checks whether or not a worth is appropriate with a knowledge sort.

    This ought to be equal to the ISNUMERIC() perform proven above:

    if Worth.Is([Value], Quantity.Sort) = true
    then Quantity.From([Value])
    else null

    Sadly, this perform didn’t return the anticipated outcome as effectively:

    Determine 5 – End result when making an attempt the Worth.Is() perform (Determine by the Writer)

    Once I tried the identical strategy as above, by changing the worth to a quantity first, I obtained the identical outcome as earlier than:

    Determine 6 – Errors when making an attempt to transform the values to a quantity first (Determine by the Writer)

    Subsequently, I think that the perform Worth.Is() expects a quantity knowledge sort, however this is senseless to me.

    At this level, I didn’t have time for deeper analysis, as I used to be operating brief on time.

    It was time to modify the strategy.

    Switching idea

    Now I explored how you can catch errors in Energy Question.

    My thought was: What if I might catch the conversion error and use this data?

    I discovered this web page with helpful data: Errors – PowerQuery M | Microsoft Learn

    From this, I deduced this expression:

    attempt Quantity.From([Value]))

    After including a calculated column with this expression, I obtained this outcome:

    Determine 7 – End result with attempt (Determine by the Writer)

    I used to be optimistic, as I didn’t get an error.

    Subsequent, was to increase the Data:

    Determine 8 – Broaden the Worth from the File output of the attempt name (Determine by the Writer)

    I didn’t want the Error columns—solely the Worth column.

    That is the outcome after the enlargement:

    Determine 9 – End result after the enlargement of the information (Determine by the Writer)

    Discover that I renamed the columns instantly within the ExpandRecordColumn() perform.
    In any other case, I’d have gotten a column named [Value.1].

    This outcome was the primary the place I didn’t get any errors.

    Now, I added a calculated column to verify if the brand new column is empty. If sure, then the unique Worth column contained a textual content:

    if [Numeric Value] = null then [Value] else null

    Right here, the outcome:

    Determine 10 – End result with the profitable separation of numerical and textual content values from one column (Determine by the Writer)

    After setting the right knowledge varieties and eradicating the unique Worth column, I obtained this desk:

    Determine 11 – End result after cleanup (Determine by the Writer)

    Deal with the quantity with blanks

    However we nonetheless have row 17, which contained a quantity with a clean.

    How did I deal with this?

    Probably the most easy strategy was to take away any Clean from the column Worth:

    Determine 12 – Add a Change Worth name to take away blanks from the info (Determine by the Writer)

    However I had so as to add this step earlier than beginning the steps for separating the 2 worth varieties:

    Determine 13 – Add the Change Worth step on the appropriate place (Determine by the Writer)

    After including this step, row 17 is acknowledged as a quantity and saved accurately.

    Right here is the info after loading it into Energy BI:

    Determine 14 – Clear knowledge after loading into Energy BI (Determine by the Writer)

    However this solely labored if the textual content values have been single phrases. It didn’t work when sentences or a number of phrases have been saved there.

    Conclusion

    This was an interesting tour into how Energy Question, or the M-language, works with knowledge varieties.

    I’m nonetheless not sure in regards to the causes of the errors.

    However I discovered how you can deal with errors, or how you can use the attempt name and deal with the output.

    This was very useful.

    Anyway, as you see with the unique worth in row 17, knowledge high quality is paramount.

    I’ve one other shopper the place customers from completely different nations are engaged on the identical Excel file with their very own quantity codecs.

    This can be a nightmare as a result of Excel is very tolerant of information varieties. It accepts every thing, even when the column is formatted as a quantity.

    In that scenario, I need to drive customers to make use of Excel’s formatting choices to make sure that numbers are persistently acknowledged as such.

    With out this, I’ve no probability to import this knowledge into Energy BI with out lots of effort to wash up the numbers.

    And keep assured that customers at all times discover a approach to mess up with numbers in Excel.

    References

    The Knowledge is created with random numbers and phrases.

    Right here is the reference for the M-Language: Power Query M formula language reference – PowerQuery M | Microsoft Learn



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleTrump’s Executive Order to Eliminate States’ AI Laws
    Next Article Creating psychological safety in the AI era
    ProfitlyAI
    • Website

    Related Posts

    Artificial Intelligence

    Why Your AI Search Evaluation Is Probably Wrong (And How to Fix It)

    March 9, 2026
    Artificial Intelligence

    Machine Learning at Scale: Managing More Than One Model in Production

    March 9, 2026
    Artificial Intelligence

    Improving AI models’ ability to explain their predictions | MIT News

    March 9, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Vilka europeiska AI-företag har utvecklat användbara LLM?

    June 9, 2025

    what enterprise leaders need to get right

    February 27, 2026

    Video Data Collection: Best Practices, Challenges & AI Use Cases

    December 16, 2025

    Merging AI and underwater photography to reveal hidden ocean worlds | MIT News

    June 25, 2025

    AI Cognitive Health Prediction

    April 10, 2025
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    Most Popular

    AI Text Classification – Use Cases, Application, Process and Importence

    April 6, 2025

    Generative AI tool helps 3D print personal items that sustain daily use | MIT News

    January 14, 2026

    Model Context Protocol (MCP) Tutorial: Build Your First MCP Server in 6 Steps

    June 11, 2025
    Our Picks

    How AI is turning the Iran conflict into theater

    March 9, 2026

    Why Your AI Search Evaluation Is Probably Wrong (And How to Fix It)

    March 9, 2026

    Machine Learning at Scale: Managing More Than One Model in Production

    March 9, 2026
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 ProfitlyAI All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.