Date.From

D

T

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

But how does it work? In this article, we’ll take a closer look at the M code behind the Date.From function and explain exactly how it converts text strings into dates.

Understanding the Date.From Function

Before we dive into the code behind the Date.From function, it’s important to understand how it works. Essentially, the function takes a text string in a specific format and converts it into a date format that can be used in your data analysis.

The text string can be in a variety of formats, including “yyyy-mm-dd”, “mm/dd/yyyy”, “dd-mm-yyyy”, and more. The function then uses this format to extract the year, month, and day values from the text string and combine them into a date format that can be used in your analysis.

The M Code Behind the Date.From Function

Now that we understand the basic functionality of the Date.From function, let’s take a closer look at the M code behind it.

The Date.From function is actually a simple wrapper for the Date.FromText function. The Date.FromText function is responsible for taking the text string and converting it into a date format that can be used in your analysis.

Here’s an example of the M code that powers the Date.From function:


let

Source = #”SomeData”,

#”Converted to Date” = Table.TransformColumns(Source, {{“DateColumn”, each Date.FromText(_, “yyyy-mm-dd”), type date}})

in

#”Converted to Date”


Let's break down this code step by step:

1. We start by defining our data source. In this case, we're calling it "SomeData".

2. Next, we use the Table.TransformColumns function to transform the "DateColumn" in our data source. This is the column that contains the text strings we want to convert to dates.

3. In the transformation, we use the Date.FromText function to convert the text strings in the "DateColumn" into date formats. We specify the format of the text strings using the "yyyy-mm-dd" argument.

4. Finally, we specify that the transformed column should be of type "date".

And that's it! This simple M code is all it takes to convert text strings into date formats using the Date.From function.

The Date.From function is an essential tool for any data analyst or Power Query user. It provides a quick and easy way to convert text strings into date formats, saving you time and effort when working with large data sets.

By understanding the M code behind the Date.From function, you can gain a deeper understanding of how it works and how you can use it to improve your data analysis.

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)