Number.FromText

D

T

The M Code Behind the Power Query M function Number.FromText

What is Number.FromText?

Number.FromText is a function in Power Query’s M language that converts text to a number. It can be extremely useful when working with data that contains numeric values stored as text. The function takes a single parameter, which is the text that needs to be converted to a number.

The M Code Behind Number.FromText

To understand the M code behind Number.FromText, let’s first take a look at the function’s syntax:


Number.FromText(text as text, optional culture as nullable text) as nullable number


The function takes two parameters: text and culture. The text parameter is the text that needs to be converted to a number. The culture parameter is an optional parameter that specifies the culture to use when converting the text to a number.

The M code behind Number.FromText is relatively simple. Here's what it looks like:


(text as text, optional culture as nullable text) as nullable number =>

Number.FromText(text, culture)


The code defines a function that takes two parameters: text and culture. The function then calls the Number.FromText function, passing in the text and culture parameters.

Using Number.FromText in Power Query

Now that we understand the M code behind Number.FromText, let's take a look at how it can be used in Power Query.

Suppose we have a table with a column called "Revenue" that contains revenue data stored as text. To convert this data to numbers, we can use the Number.FromText function in Power Query.

First, we need to add a new column to our table by clicking the "Add Column" tab and selecting "Custom Column". In the "Custom Column" dialog box, we can enter the following formula:


Number.FromText([Revenue])


This formula tells Power Query to convert the text in the "Revenue" column to a number using the Number.FromText function. Once we click "OK", Power Query will add a new column to our table containing the converted revenue data.

The Number.FromText function is an extremely useful function in Power Query's M language. It allows users to convert text to numbers, which can be crucial when working with data that contains numeric values stored as text. By understanding the M code behind Number.FromText, users can better utilize this function in their data transformation operations.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)