Double.From

D

T

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

The Double.From function is written in the M language, which is the language used by Power Query to control the data transformation process. Understanding the M code behind the Double.From function can be helpful when working with large or complex datasets.

Syntax of the Double.From Function

The syntax of the Double.From function is as follows:


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


The Double.From function takes two arguments:

- `text`: The text value to convert to a double.

- `culture`: An optional argument that specifies the culture to use when converting the text value to a double.

The function returns a nullable number value.

Understanding the M Code Behind the Double.From Function

The M code behind the Double.From function can be broken down into three parts:

1. Input validation and error handling

2. Parsing the text value to a double

3. Returning the double value

Input Validation and Error Handling

The input validation and error handling section of the code ensures that the input value is valid and that no errors occur during the conversion process. The code checks if the input value is null or blank and returns a null value if true. It also checks if the text value can be converted to a double and returns an error if it cannot.

Parsing the Text Value to a Double

The code then proceeds to parse the text value to a double. It first checks if the culture argument has been specified. If it has, the code uses that culture to parse the text value to a double. If the culture argument has not been specified, the code uses the default culture of the system.

The code uses the NumberStyles.Float flag to indicate that the text value is a floating-point value. It also uses the CultureInfo object to specify the culture to use when parsing the text value. The code then uses the Double.TryParse method to parse the text value to a double.

Returning the Double Value

Finally, the code returns the double value. If the text value cannot be parsed to a double, the code returns a null value. If the text value can be parsed to a double, the code returns the double value.

Understanding the M code behind the Power Query M function Double.From can be helpful when working with large or complex datasets. The Double.From function allows users to convert text values to numeric values in Power Query, making it a powerful tool for data transformation. By breaking down the M code behind the function, users can gain a deeper understanding of how the function works and how it can be used to solve data transformation challenges.

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)