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
Awollet33
Helper I
Helper I

Looking to find time currency by minute

Hi All - 

 

I have the datetime of the stop and start times of the surgieries going on at a hospital. I am trying to find out how many surgeries are happening in the hospital by minute. It has to be by minute. Does anyone have any experince working with a datetime range and finding concurrency by minute? I was hoping I could expand the table by the datetime range to create a row for every minute.

 

Any and all ideas are appreciated!!! Thanks for the help - Adam

1 ACCEPTED SOLUTION

Have a look at this demo

In steps:

 

1) Started with a basic table:

bcdobbs_0-1642005620223.png

2) In power query broke apart the date and times:

bcdobbs_1-1642005666254.png

3) Changed the original datetimes to decimals.

4) Created custom columns multipling the start and end decimals by 24*60. (1 day equals 1 so this returns a whole number of minutes since 30 December 1899. )

bcdobbs_2-1642005810124.png

Full M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI00jcw1DcyMDJSMLC0MjDAEDI2UIrViVYyAkkYIyQsQBIoQoYGIO0gtcZoamHmIqk1BKuNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SurgeryId = _t, #"DateTime Start" = _t, #"DateTime End" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"SurgeryId", Int64.Type}, {"DateTime Start", type datetime}, {"DateTime End", type datetime}}),
    AddDateStart = Table.AddColumn(ChangedType, "Date Start", each DateTime.Date([DateTime Start])),
    AddDateEnd = Table.AddColumn(AddDateStart, "Date End", each DateTime.Date([DateTime End])),
    AddTimeStart = Table.AddColumn(AddDateEnd, "Time Start", each DateTime.Time([DateTime Start])),
    AddTimeEnd = Table.AddColumn(AddTimeStart, "Time End", each DateTime.Time([DateTime End])),
    ChangedType2 = Table.TransformColumnTypes(AddTimeEnd,{{"DateTime Start", type number}, {"DateTime End", type number}}),
    AddMinuteStartStamp = Table.AddColumn(ChangedType2, "MinuteStartStamp", each [DateTime Start]*24*60),
    AddMinuteEndStamp = Table.AddColumn(AddMinuteStartStamp, "MinuteEndStamp", each [DateTime End] * 24 * 60),
    ChangedType3 = Table.TransformColumnTypes(AddMinuteEndStamp,{{"MinuteStartStamp", Int64.Type}, {"MinuteEndStamp", Int64.Type}}),
    RemovedOtherColumns = Table.SelectColumns(ChangedType3,{"SurgeryId", "Date Start", "Date End", "Time Start", "Time End", "MinuteStartStamp", "MinuteEndStamp"})
in
    RemovedOtherColumns

6) Use the following DAX to create a table at minute grain:

ExpandedTable = 
    GENERATE (
        OriginalTable,
        VAR CurrentStart = OriginalTable[MinuteStartStamp]
        VAR CurrentEnd = OriginalTable[MinuteEndStamp]
        RETURN
            GENERATESERIES( CurrentStart, CurrentEnd, 1 )
    )

7) Rename the VALUE column to "Minute Stamp".

I'd like to be able to do that all in PowerQuery but can't quite make it work at the moment. Will update if I sort it.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

5 REPLIES 5
Awollet33
Helper I
Helper I

Hi @bcdobbs ,

Thank you so much for your help and detailed answer. I am just am seeing it now and I am going to look through the information you provided and it give it a try. Super excited to try and crack this problem as it will be a great help to our hospital. 

 

Thanks,

Adam

bcdobbs
Super User
Super User

Not done it at the minute grain but often do expand day start/end to a table at the day grain which is done using:

TableExpanded = 
    GENERATE (
        OriginalTable,
        DATESBETWEEN('Calendar'[Date], OriginalTable[Start Date], OriginalTable[End Date] )
    )


I think if you create a time table at the minute grain you sould be able to the same to expand it.

If you can provide some demo data we could try and work it out.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Actually there's no MINUTESBETWEEN function so need to give that bit more thought. Thinking generateseries might help but need to have a play.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Have a look at this demo

In steps:

 

1) Started with a basic table:

bcdobbs_0-1642005620223.png

2) In power query broke apart the date and times:

bcdobbs_1-1642005666254.png

3) Changed the original datetimes to decimals.

4) Created custom columns multipling the start and end decimals by 24*60. (1 day equals 1 so this returns a whole number of minutes since 30 December 1899. )

bcdobbs_2-1642005810124.png

Full M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI00jcw1DcyMDJSMLC0MjDAEDI2UIrViVYyAkkYIyQsQBIoQoYGIO0gtcZoamHmIqk1BKuNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SurgeryId = _t, #"DateTime Start" = _t, #"DateTime End" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"SurgeryId", Int64.Type}, {"DateTime Start", type datetime}, {"DateTime End", type datetime}}),
    AddDateStart = Table.AddColumn(ChangedType, "Date Start", each DateTime.Date([DateTime Start])),
    AddDateEnd = Table.AddColumn(AddDateStart, "Date End", each DateTime.Date([DateTime End])),
    AddTimeStart = Table.AddColumn(AddDateEnd, "Time Start", each DateTime.Time([DateTime Start])),
    AddTimeEnd = Table.AddColumn(AddTimeStart, "Time End", each DateTime.Time([DateTime End])),
    ChangedType2 = Table.TransformColumnTypes(AddTimeEnd,{{"DateTime Start", type number}, {"DateTime End", type number}}),
    AddMinuteStartStamp = Table.AddColumn(ChangedType2, "MinuteStartStamp", each [DateTime Start]*24*60),
    AddMinuteEndStamp = Table.AddColumn(AddMinuteStartStamp, "MinuteEndStamp", each [DateTime End] * 24 * 60),
    ChangedType3 = Table.TransformColumnTypes(AddMinuteEndStamp,{{"MinuteStartStamp", Int64.Type}, {"MinuteEndStamp", Int64.Type}}),
    RemovedOtherColumns = Table.SelectColumns(ChangedType3,{"SurgeryId", "Date Start", "Date End", "Time Start", "Time End", "MinuteStartStamp", "MinuteEndStamp"})
in
    RemovedOtherColumns

6) Use the following DAX to create a table at minute grain:

ExpandedTable = 
    GENERATE (
        OriginalTable,
        VAR CurrentStart = OriginalTable[MinuteStartStamp]
        VAR CurrentEnd = OriginalTable[MinuteEndStamp]
        RETURN
            GENERATESERIES( CurrentStart, CurrentEnd, 1 )
    )

7) Rename the VALUE column to "Minute Stamp".

I'd like to be able to do that all in PowerQuery but can't quite make it work at the moment. Will update if I sort it.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Version entirely in PowerQuery which I think is tidier.

 

Just needed to add an extra column in power query with following:

List.Numbers([MinuteStartStamp], [MinuteEndStamp]-[MinuteStartStamp] + 1, 1)

 

That column can then expand to new rows.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

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.