The M Code Behind the Power Query M function Decimal.From

In this article, we will explore the M code behind the Decimal.From function and demonstrate how it can be used to convert text values to decimal numbers in Power Query.

Understanding the Decimal.From Function

The Decimal.From function in Power Query M is used to convert a text value to a decimal number. This can be particularly useful when working with data that contains numeric values stored as text.

The syntax for the Decimal.From function is as follows:

Decimal.From(text as text, optional culture as nullable text) as nullable number

The function takes two parameters. The first parameter, "text," is the text value that you want to convert to a decimal number. The second parameter, "culture," is an optional parameter that specifies the culture to use when converting the text value to a decimal number. If the culture parameter is not specified, the function will use the current culture of the system.

Using Decimal.From in Power Query

To use the Decimal.From function in Power Query, you can follow these steps:

1. Open the Power Query Editor in Excel.

2. Select the column containing the text values that you want to convert to decimal numbers.

3. Click on the "Transform Data" button in the "Home" tab to open the Power Query Editor.

4. In the Power Query Editor, click on the "Add Column" tab and select "Custom Column" from the dropdown menu.

5. In the "Custom Column" dialog box, enter a name for the new column.

6. In the "Custom Column" dialog box, enter the following expression:

Decimal.From([Text Column])

7. Click "OK" to create the new column.

This will create a new column containing the decimal values that were converted from the text values in the original column.

Understanding the M Code Behind Decimal.From

To understand the M code behind the Decimal.From function, we can look at the following example:


Source = #table({“Text Value”}, {{“123.45”}}),

#”Changed Type” = Table.TransformColumnTypes(Source,{{“Text Value”, type text}}),

#”Added Custom” = Table.AddColumn(#”Changed Type”, “Decimal Value”, each Decimal.From([Text Value])),

#”Removed Columns” = Table.RemoveColumns(#”Added Custom”,{“Text Value”})


#”Removed Columns”

This M code creates a table with one column called "Text Value" and one row with the value "123.45." The code then converts the "Text Value" column to type text and adds a new column called "Decimal Value" using the Decimal.From function. Finally, the code removes the "Text Value" column to leave only the "Decimal Value" column.

In conclusion, the Decimal.From function is a powerful tool in Power Query M that allows users to convert text values to decimal numbers. By understanding the syntax and usage of the function, users can easily transform and manipulate data in Excel to better meet their needs.

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

Upcoming Courses

Contact Us


    Your Name (required)


    Email (required)


    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)