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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Mengeltje
Frequent Visitor

How to split time interval rows into quarters

Tried this with Copilot but didn't get it worked.

 

It's about the registration of time of people working. I get an Excel with for example the following info:

Column 1Column 2Column 3Column 4
19-1-2024 00:0019-1-2024 12:1519-1-2024 13:00Lunch
20-1-2024 00:0020-1-2024 12:1520-1-2024 12:45Out

 

This file is imported in Power BI but I need this per quarter:

 

Column 1Column 2Column 3Column 4
19-1-2024 00:0019-1-2024 12:1519-1-2024 12:30Lunch
19-1-2024 00:0019-1-2024 12:3019-1-2024 12:45Lunch
19-1-2024 00:0019-1-2024 12:4519-1-2024 13:00Lunch
20-1-2024 00:0020-1-2024 12:1520-1-2024 12:30Out
20-1-2024 00:0020-1-2024 12:3020-1-2024 12:45Out

 

Hope someone can help me!

Thanks in advance!

2 ACCEPTED SOLUTIONS
DataNinja777
Super User
Super User

Hi @Mengeltje ,

 

To transform your data into 15-minute intervals in Power BI, you can use Power Query to automate the process. Load your table into Power Query and open the Advanced Editor. Replace the existing code with the following script:

 

let
    Source = <Your Table Name>,  // Replace with your actual table name
    AddQuarterIntervals = Table.AddColumn(Source, "QuarterIntervals", each 
        List.Transform(
            List.Numbers(0, Number.RoundUp(Duration.TotalMinutes(Duration.From([Column3] - [Column2])) / 15)),
            each [Column2] + #duration(0, 0, 15) * _
        )
    ),
    ExpandQuarterIntervals = Table.ExpandListColumn(AddQuarterIntervals, "QuarterIntervals"),
    AdjustEndTime = Table.AddColumn(ExpandQuarterIntervals, "NewEndTime", each 
        if [QuarterIntervals] + #duration(0, 0, 15) > [Column3] then [Column3] else [QuarterIntervals] + #duration(0, 0, 15)
    ),
    RemoveExtraColumns = Table.SelectColumns(AdjustEndTime, {"Column1", "QuarterIntervals", "NewEndTime", "Column4"}),
    RenameColumns = Table.RenameColumns(RemoveExtraColumns, {{"QuarterIntervals", "Column2"}, {"NewEndTime", "Column3"}})
in
    RenameColumns

 

This script works by first generating a list of 15-minute intervals between the start (Column2) and end (Column3) times for each row. These intervals are expanded into individual rows to create the desired breakdown. A new column (NewEndTime) is calculated to ensure that each interval's end time aligns with either the next 15-minute mark or the original end time. Unnecessary columns used for intermediate calculations are then removed, leaving only the required fields. Finally, the columns are renamed to match your desired format.

When applied, this script will transform your data so that each original time range is split into rows representing 15-minute intervals, while preserving all necessary information from the original table. If you encounter any issues or need further clarification, feel free to ask.

 

Best regards,

View solution in original post

danextian
Super User
Super User

Hi @Mengeltje 

 

Here's a sample query

danextian_0-1733411067039.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrTUNzDUNzIwMlEwsDIwUNJBFjE0sjI0RRMyhqjyKc1LzlCK1YlWMjJANwFJBGYCqpAJSMi/tEQpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Start = _t, End = _t, Remarks = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Start", type datetime}, {"End", type datetime}, {"Remarks", type text}}),
    #"Extracted Date" = Table.TransformColumns(#"Changed Type",{{"Date", DateTime.Date, type date}}),
    #"Added Custom" = Table.AddColumn(#"Extracted Date", "Split", each let
    // Define the start and end times
    StartTime =[Start],
    EndTime = [End],

    // Generate a list of times with 15-minute intervals
    TimeList = List.Generate(
        () => StartTime, 
        each _ < EndTime, 
        each _ + #duration(0, 0, 15, 0)  // Add 15 minutes using #duration
    ),

    // Convert the list into a table
    TimeTable = Table.FromList(TimeList, Splitter.SplitByNothing(), {"Start Time"}),

    // Add the End Time by adding 15 minutes to each Start Time
    AddEndTime = Table.AddColumn(TimeTable, "End Time", each [Start Time] + #duration(0, 0, 15, 0))
in
    AddEndTime),
    //Expanded the generate column of time tables
    #"Expanded Split" = Table.ExpandTableColumn(#"Added Custom", "Split", {"Start Time", "End Time"}, {"Start Time", "End Time"})
in
    #"Expanded Split"




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

2 REPLIES 2
danextian
Super User
Super User

Hi @Mengeltje 

 

Here's a sample query

danextian_0-1733411067039.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrTUNzDUNzIwMlEwsDIwUNJBFjE0sjI0RRMyhqjyKc1LzlCK1YlWMjJANwFJBGYCqpAJSMi/tEQpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Start = _t, End = _t, Remarks = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Start", type datetime}, {"End", type datetime}, {"Remarks", type text}}),
    #"Extracted Date" = Table.TransformColumns(#"Changed Type",{{"Date", DateTime.Date, type date}}),
    #"Added Custom" = Table.AddColumn(#"Extracted Date", "Split", each let
    // Define the start and end times
    StartTime =[Start],
    EndTime = [End],

    // Generate a list of times with 15-minute intervals
    TimeList = List.Generate(
        () => StartTime, 
        each _ < EndTime, 
        each _ + #duration(0, 0, 15, 0)  // Add 15 minutes using #duration
    ),

    // Convert the list into a table
    TimeTable = Table.FromList(TimeList, Splitter.SplitByNothing(), {"Start Time"}),

    // Add the End Time by adding 15 minutes to each Start Time
    AddEndTime = Table.AddColumn(TimeTable, "End Time", each [Start Time] + #duration(0, 0, 15, 0))
in
    AddEndTime),
    //Expanded the generate column of time tables
    #"Expanded Split" = Table.ExpandTableColumn(#"Added Custom", "Split", {"Start Time", "End Time"}, {"Start Time", "End Time"})
in
    #"Expanded Split"




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
DataNinja777
Super User
Super User

Hi @Mengeltje ,

 

To transform your data into 15-minute intervals in Power BI, you can use Power Query to automate the process. Load your table into Power Query and open the Advanced Editor. Replace the existing code with the following script:

 

let
    Source = <Your Table Name>,  // Replace with your actual table name
    AddQuarterIntervals = Table.AddColumn(Source, "QuarterIntervals", each 
        List.Transform(
            List.Numbers(0, Number.RoundUp(Duration.TotalMinutes(Duration.From([Column3] - [Column2])) / 15)),
            each [Column2] + #duration(0, 0, 15) * _
        )
    ),
    ExpandQuarterIntervals = Table.ExpandListColumn(AddQuarterIntervals, "QuarterIntervals"),
    AdjustEndTime = Table.AddColumn(ExpandQuarterIntervals, "NewEndTime", each 
        if [QuarterIntervals] + #duration(0, 0, 15) > [Column3] then [Column3] else [QuarterIntervals] + #duration(0, 0, 15)
    ),
    RemoveExtraColumns = Table.SelectColumns(AdjustEndTime, {"Column1", "QuarterIntervals", "NewEndTime", "Column4"}),
    RenameColumns = Table.RenameColumns(RemoveExtraColumns, {{"QuarterIntervals", "Column2"}, {"NewEndTime", "Column3"}})
in
    RenameColumns

 

This script works by first generating a list of 15-minute intervals between the start (Column2) and end (Column3) times for each row. These intervals are expanded into individual rows to create the desired breakdown. A new column (NewEndTime) is calculated to ensure that each interval's end time aligns with either the next 15-minute mark or the original end time. Unnecessary columns used for intermediate calculations are then removed, leaving only the required fields. Finally, the columns are renamed to match your desired format.

When applied, this script will transform your data so that each original time range is split into rows representing 15-minute intervals, while preserving all necessary information from the original table. If you encounter any issues or need further clarification, feel free to ask.

 

Best regards,

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.