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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

help with power query

Hello,

 I have a data set for bike rental  with start date and time and end date and time. now, i want to calculate the difference between the start date and and time and end date and time. for example if a bike starts at 06.00 am on 7/2/2016 and ends on 7/3/2016 at 4.30 am the no of hours between them must be calculated which is 22 hours  and per each hours i want to print a new row with all the data included and the updated hour. for example :

#row1 trip id 1 , start time and date 7/2/2016 06:00 am

#row 2 trip id 1, start time and date 7/2/2016 07:00 am

#row 3 trip id 1, start time and date 7/2/2016 08:00 am 

#row 3 trip id 1, start time and date 7/2/2016 09:00 am ..........so ontrip id 1, till 7/3/2016 04:00am 

 

i have tried using the 

  1. temp ={Number.From([Start_date])..Number.From([End_date])}
  2. A list is generated expanded it and changed to date 
  3. if ( [Temp] = [StartDate]) then [StartTime] else [Temp]
  4. if ([Temp] = [EndDate]) then [EndTime] else [Temp] & #time(23,59,59) but, it dint work. i am attaching a screen shot for reference. Thank you for the help in advance. sample data  with date and time , excluding other multiple columnssample data with date and time , excluding other multiple columns
1 ACCEPTED SOLUTION
Anonymous
Not applicable

thank you for the kind reply.

https://www.dropbox.com/s/oiodhrh5255bt8a/sampledatafor2016.xlsx?dl=0

but my data is not just for one day, i am sorry i was not clear with the question, i am very new to power bi and power queries. i have added a sample link for the file, it goes for 2016, july to end of year. and when i try to do this way , i am getting an error. list.dates gives list only for a month, actually i have data from july, 2016  to ,2017,2018, 2019 years . since power bi is not allowing me to have 24 hours  rows for all these years in same table, i split them in multiple tables yearly.

 

could you check the sample data and suggest me some solution. 

View solution in original post

2 REPLIES 2
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

One sample for your reference. Please check the following steps as below.

 

1. Create a table in power query like this.

let
    Source = List.Dates(#date(2016,7,1), 3, #duration(1,0,0,0)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Date"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each {0..23}),
    #"Expanded {0}" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Added Custom1" = Table.AddColumn(#"Expanded {0}", "DateTime", each DateTime.From([Date])+#duration(0,[Custom],0,0))
in
    #"Added Custom1"

2. Close and apply, then we can create a calculated table based on it.

 

Table 2 = var a =ADDCOLUMNS(CROSSJOIN(Query1,'Table'),"st",'Table'[start time],"ed",'Table'[end time])
var b =FILTER(a,[DateTime]>=[st] && [DateTime]<=[ed])
return
b

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

thank you for the kind reply.

https://www.dropbox.com/s/oiodhrh5255bt8a/sampledatafor2016.xlsx?dl=0

but my data is not just for one day, i am sorry i was not clear with the question, i am very new to power bi and power queries. i have added a sample link for the file, it goes for 2016, july to end of year. and when i try to do this way , i am getting an error. list.dates gives list only for a month, actually i have data from july, 2016  to ,2017,2018, 2019 years . since power bi is not allowing me to have 24 hours  rows for all these years in same table, i split them in multiple tables yearly.

 

could you check the sample data and suggest me some solution. 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors