Date.IsInCurrentDay

Date.IsInCurrentDay

D

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

What is the Date.IsInCurrentDay function?

The Date.IsInCurrentDay function is a Power Query M function that can be used to determine if a given date falls within the current day. It takes a single argument, which is the date that needs to be checked. If the date falls within the current day, the function returns true. If the date does not fall within the current day, the function returns false.

How does the Date.IsInCurrentDay function work?

The Date.IsInCurrentDay function works by first retrieving the current date and time using the DateTime.LocalNow function. This returns a datetime value that represents the current date and time on the computer that is running the Power Query query.

Next, the function extracts the date portion of the current datetime value using the Date.From function. This returns a date value that represents the current date.

Finally, the function compares the input date to the current date by checking if the input date is equal to the current date using the Date.Equals function. If the input date is equal to the current date, the function returns true. Otherwise, it returns false.

Using the Date.IsInCurrentDay function

The Date.IsInCurrentDay function can be very useful when working with date ranges in Power Query. For example, you may want to filter a table to only include rows where the date falls within the current day. To do this, you can use the Date.IsInCurrentDay function in combination with the Table.SelectRows function.

Here’s an example of how this can be done:


let

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(“i45WMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWIVkZUeD0pMLCvVi1WqZgB”, BinaryEncoding.Base64)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#”Date” = _t]),

#”Changed Type” = Table.TransformColumnTypes(Source,{{“Date”, type date}})

in

#”Changed Type”


This code creates a table with a single column called "Date" that contains a list of dates. To filter this table to only include rows where the date falls within the current day, we can add the following code:


let

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(“i45WMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWMlSK1YlWIVkZUeD0pMLCvVi1WqZgB”, BinaryEncoding.Base64)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#”Date” = _t]),

#”Changed Type” = Table.TransformColumnTypes(Source,{{“Date”, type date}}),

#”Filtered Rows” = Table.SelectRows(#”Changed Type”, each Date.IsInCurrentDay([Date]))

in

#”Filtered Rows”


This code first transforms the "Date" column to a date data type using the Table.TransformColumnTypes function. Next, it uses the Table.SelectRows function to filter the table to only include rows where the date falls within the current day. This is done by passing the Date.IsInCurrentDay function as the filter expression.

The Date.IsInCurrentDay function is a useful Power Query M function that can be used to determine if a given date falls within the current day. It can be used in combination with other Power Query functions to filter tables or perform other data manipulation tasks. By understanding how this function works, you can improve your data transformation skills in Power Query and become more efficient at working with 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: