DateTime.FixedLocalNow

DateTime.FixedLocalNow

D

The M Code Behind the Power Query M function DateTime.FixedLocalNow

What is DateTime.FixedLocalNow?

The DateTime.FixedLocalNow function is an M function that returns a fixed date and time value in the local time zone. This function is useful when you need to add a timestamp to your data. It returns the current date and time in the local time zone, which is based on the time zone of the computer that is running the Power Query.

The syntax for the DateTime.FixedLocalNow function is as follows:


DateTime.FixedLocalNow()


This function does not take any arguments. It simply returns the current date and time in the local time zone.

Understanding the M Code Behind DateTime.FixedLocalNow

To understand the M code behind the DateTime.FixedLocalNow function, we need to break it down into its individual components. The M code for this function is as follows:


DateTime.FixedLocalNow = () =>

DateTime.LocalNow() & “Z”,

type text


Let's break down this code into its individual components:

- `DateTime.FixedLocalNow`: This is the name of the function. It is a user-defined function that has been created using the `=` operator.

- `() =>`: This is a lambda operator that is used to define the function. The `()` indicates that this function does not take any arguments.

- `DateTime.LocalNow()`: This is a built-in M function that returns the current date and time in the local time zone. It is used to get the current date and time value.

- `& "Z"`: This concatenates the letter "Z" to the end of the date and time value. This is used to indicate that the date and time value is in UTC format.

- `type text`: This specifies the data type of the function output. In this case, it is text.

How to Use DateTime.FixedLocalNow in Power Query

Now that we understand the M code behind the DateTime.FixedLocalNow function, let's see how we can use it in Power Query to manipulate and extract data.

Suppose we have a table that contains customer orders. We want to add a timestamp column to this table that shows the date and time the order was placed. We can use the DateTime.FixedLocalNow function to achieve this.

1. Open Power Query and load the customer orders table.

2. Select the "Add Column" tab and click on "Custom Column".

3. In the "Custom Column" dialog box, enter a name for the new column (e.g. "Timestamp") and enter the following M code:


DateTime.FixedLocalNow()


4. Click on "OK" to add the new column to the table.

The new "Timestamp" column will contain the current date and time value in the local time zone. This column can be used to track when orders were placed and to sort orders by the time they were placed.

The DateTime.FixedLocalNow function is a useful M function in Power Query that can be used to add timestamps to data. It returns the current date and time value in the local time zone and can be used to track when data was extracted, transformed, and loaded. By understanding the M code behind this function, users can use it to perform more complex data transformations and extract insights from their data.

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)

Copyright, G Com Solutions Ltd, 2024.
Tower Bridge Business Centre, 46-48 East Smithfield, London E1W 1AW
0800 998 9248   |   9:00 a.m. till 5:30 p.m.

Connect With Me: