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
Anonymous
Not applicable

Expand Dates and Times

Hello,

 

I have a data set as below:

 

Capture.PNG

I need to expand the Minutes with respective to date and Value.

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This Mo code gets close but returns 2 additional rows (see last 2 rows).  I cannot spot my error

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date and Time", type datetime}, {"End Date and Time", type datetime}, {"Value", type text}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Break out rows", each 60*24*([End Date and Time]-[Start Date and Time])/30),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Break out rows", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each List.DateTimes([Start Date and Time], Duration.Hours([End Date and Time]-[Start Date and Time])+[Break out rows], #duration(0,0,30,0))),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Start Date and Time", "End Date and Time", "Break out rows"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "Value"})
in
    #"Reordered Columns"

Hope this helps.

Untitled.png


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

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

This Mo code gets close but returns 2 additional rows (see last 2 rows).  I cannot spot my error

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date and Time", type datetime}, {"End Date and Time", type datetime}, {"Value", type text}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Break out rows", each 60*24*([End Date and Time]-[Start Date and Time])/30),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Break out rows", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each List.DateTimes([Start Date and Time], Duration.Hours([End Date and Time]-[Start Date and Time])+[Break out rows], #duration(0,0,30,0))),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Start Date and Time", "End Date and Time", "Break out rows"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "Value"})
in
    #"Reordered Columns"

Hope this helps.

Untitled.png


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

Hi,

 

Thank you for your Post.

 

I did one small change in the code as bold lettered below and got the final Output. It works!!!

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date and Time", type datetime}, {"End Date and Time", type datetime}, {"Value", type text}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type", "Break out rows", each 24*(60*([End Date and Time]-[Start Date and Time]))/30),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Break out rows", type number}}),
#"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each List.DateTimes([Start Date and Time], ([Break out rows]+1), #duration(00,00,30,00))),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Start Date and Time", "End Date and Time", "Break out rows"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "Value"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Reordered Columns",{{"Custom", type datetime}})
in
#"Changed Type2"

Thank you for sharing this.  By increasing the count by 1, how are the number of rows reducing?  I do not understand.


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

Break out rows = 24*(60*([End Date and Time]-[Start Date and Time]))/30

 

This Custom column basically calculates the count of 30 mins interval between two times. For Ex: if start time is 3:30 AM and end time is 5:00 AM, the output in Break out rows is 3 ( 4:00, 4:30, 5:00).

 

Custom = List.DateTimes([Start Date and Time], ([Break out rows]+1), #duration(00,00,30,00))

 

The above function will list the date with time. First value is the Start time and the count of rows it should list is Break out rows + 1 and the interval is 30mins.

 

so the output will times as below:

 

3:30

4:00

4:30

5:00

 

Note: I didn't mention dates here to illustrate. Hope this helps!

Hi @Anonymous 

 

Could you tell me if your problem has been solved? If it is,kindly mark the helpful answer as a solution if you feel that makes sense. Welcome to share your own solution. More people will benefit from here.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

Thank you.


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

Thanks for your response. Could you please explain me the steps applied?

 

That extra rows were there couldn't remove. Please help me with steps so that I can have better understanding and transform the dataset to get the desired output without extra rows.

Hi,

Kinldy click on each step in the Applied steps box and try to understand them yourself.


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

You can use List.DateTimes. The syntax of List.DateTimes is (start as datetime, count as number, step as duration). Start as daytime is the Start Datetime. Count= how many 30 minutes interval occur between start and finish date time. For step you need to use #duration. You will have what you need woth this.
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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.