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
Tevon713
Helper IV
Helper IV

User input for time and calculate duration

I need help in building a free form where user to input field "start time and end time" and then aggregate it to find total minutes. Maybe a simple parameters maybe have 2 different forms then a measure to calculate it.  Below is excel, how would I achieve this in pbi? Thank you all.

 

Excel model:

Tevon713_0-1667575616228.png

 

 

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Tevon713 ,

 

Here are the steps you can follow:

1. Home – Advanced Editor --Put the following code .

Generate a calendar table with HH:MM:S and copy the columns, then copy the table

let
    Source = List.Times(#time(0,0,0),24*60*60,#duration(0,0,0,1)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Time"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Time", type time}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Time", "Time - Copy")
in
    #"Duplicated Column"

vyangliumsft_0-1667795361262.png

2. Convert the columns [Time] of both tables to text, Column tools – Text.

vyangliumsft_1-1667795361266.png

3. Generate a slicer for the [Time] of both tables - click the ellipsis -Search - then you can enter the date on this.

vyangliumsft_2-1667795361267.png

4. Create measure.

Measure =
var _starttimetext=SELECTEDVALUE('StartTable'[Time])
var _endtimetext=SELECTEDVALUE('EndTable'[Time])
var _start=MAXX(FILTER(ALL(StartTable),'StartTable'[Time]=_starttimetext),[Time - Copy])
var _end=MAXX(FILTER(ALL(EndTable),'EndTable'[Time]=_endtimetext),[Time - Copy])
return
DATEDIFF(_start,_end,MINUTE)

5. Result:

vyangliumsft_3-1667795361269.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Tevon713 ,

 

Here are the steps you can follow:

1. Home – Advanced Editor --Put the following code .

Generate a calendar table with HH:MM:S and copy the columns, then copy the table

let
    Source = List.Times(#time(0,0,0),24*60*60,#duration(0,0,0,1)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Time"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Time", type time}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Time", "Time - Copy")
in
    #"Duplicated Column"

vyangliumsft_0-1667795361262.png

2. Convert the columns [Time] of both tables to text, Column tools – Text.

vyangliumsft_1-1667795361266.png

3. Generate a slicer for the [Time] of both tables - click the ellipsis -Search - then you can enter the date on this.

vyangliumsft_2-1667795361267.png

4. Create measure.

Measure =
var _starttimetext=SELECTEDVALUE('StartTable'[Time])
var _endtimetext=SELECTEDVALUE('EndTable'[Time])
var _start=MAXX(FILTER(ALL(StartTable),'StartTable'[Time]=_starttimetext),[Time - Copy])
var _end=MAXX(FILTER(ALL(EndTable),'EndTable'[Time]=_endtimetext),[Time - Copy])
return
DATEDIFF(_start,_end,MINUTE)

5. Result:

vyangliumsft_3-1667795361269.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thanks @v-yangliu-msft. Not exactly what I'm seeking, but I can find way around it. Thank you again.

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.