Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
まもる
Frequent Visitor

Automatic generation of date and time data of power query

Please let me know if you know.
I want to automatically generate date and time data every 5 minutes with "power query".

 

For example:
Start date and time 2018/11/20 0:45:00, End time is continuous.

 

The data I want (every 5 minutes)
2018/11/20 0:45:00
2018/11/20 0:50:00
2018/11/20 0:55:00
2018/11/20 1:00:00
2018/11/20 1:05:00
2018/11/20 1:10:00
2018/11/20 1:15:00


2018/11/26 10:25:00
2018/11/26 10:30:00

 

I need it in Power Query so I can then perform a merge to another table later.

Hope someone can help with this.

 

Best Regards,

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

This M code will create 10 Date/Time entries

 

let
    Date = List.DateTimes(#datetime(2018, 11, 20, 00, 45, 0), 10, #duration(0, 0, 5, 0))
in
    Date

 

Read more here - https://docs.microsoft.com/en-us/powerquery-m/list-datetimes

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

13 REPLIES 13
Ashish_Mathur
Super User
Super User

Hi,

 

This M code will create 10 Date/Time entries

 

let
    Date = List.DateTimes(#datetime(2018, 11, 20, 00, 45, 0), 10, #duration(0, 0, 5, 0))
in
    Date

 

Read more here - https://docs.microsoft.com/en-us/powerquery-m/list-datetimes

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur

@Anonymous

 

Hello.
Thank you for your information.
It's perfect!

Thank you very much.

 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur

 

I'm so sorry.  I have an additional question.
Instead of creating a list of 10 values, Can you make it infinite?

 

I can not speak English.  I'm sorry if English was wrong.
Thank you.

Hi,

 

Specify the year as 2999.  It should be as good as infinite


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/


Hello.  Thank you for your information.
But, How can I specify the year as 2999?

 

This is a mistake.
-----
= List.DateTimes(#datetime(2018, 11, 20, 00, 45, 0), EndOfYear 2999, #duration(0, 0, 5, 0))
-----

 

Please, help me.

Hi,

 

This should give you 3000 lines

 

Date = List.DateTimes(#datetime(2018, 11, 20, 00, 45, 0), 3000, #duration(0, 0, 5, 0))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello.  Thank you for your advice.

 

I need to merge the date and time data created here with the continuation data of another table.
(The data to be merged is added every 5 minutes.)
So, 3000 lines is not enough.

 

Do you have any good ideas?

You are welcome.  No, i do not hav any better ideas.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello.
Thank you very much for letting me know many things for a long time.

 

Best Regards,

by Mamoru

Anonymous
Not applicable

Oh thats way better. I'm shameless stealing this.

Thank you.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Create 2 tables.  One table with all of the dates you want.  The other with all of the times you want.  Do a Merge of these tables by adding a column references the entire other table.

 

Here is an example:

Dates:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMLRQitWJVjJC5hjDObEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}})
in
    #"Changed Type"

Times:

 

DateTimes:

let
    Source = Dates,
    #"Added Merge" = Table.AddColumn(Source, "Times", each #"Times"),
    #"Expanded Times" = Table.ExpandTableColumn(#"Added Merge", "Times", {"Times"}, {"Time"}),
    #"Added Combined" = Table.AddColumn(#"Expanded Times", "Custom", each Text.From([Date]) & " " & Text.From([Time])),
    #"Change to DateTime" = Table.TransformColumnTypes(#"Added Combined",{{"Custom", type datetime}})
in
    #"Change to DateTime"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.