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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Jramirej
Regular Visitor

Create calculated table to generate new rows as per column value

Hi Team,

I am searching for one solution over the internet but am unable to find one. Your support is highly appreciated.
I have data like below
Appointment Date & Time data format is DateTime

Task Appointment Date & TimeDuration (Mins)
Meeting with Mr A14-02-2024 02:5510
Eye Checkup01-03-2024 07:005

 

As you find the 1st Task for 10 Minutes, that means for 10 mins time the doctor is not available for another task. So I have to generate one calculated table like below

Task Appointment Date & TimeDuration (Mins)
Meeting with Mr A14-02-2024 02:551
Meeting with Mr A14-02-2024 02:561
Meeting with Mr A14-02-2024 02:571
Meeting with Mr A14-02-2024 02:581
Meeting with Mr A14-02-2024 02:591
Meeting with Mr A14-02-2024 03:001
Meeting with Mr A14-02-2024 03:011
Meeting with Mr A14-02-2024 03:021
Meeting with Mr A14-02-2024 03:031
Meeting with Mr A14-02-2024 03:041
Eye Checkup01-03-2024 07:001
Eye Checkup01-03-2024 07:011
Eye Checkup01-03-2024 07:021
Eye Checkup01-03-2024 07:031
Eye Checkup01-03-2024 07:041


Logic - 

Jramirej_1-1707844571351.png


Thank you in Advance

1 ACCEPTED SOLUTION
amustafa
Solution Sage
Solution Sage

Alright, DAX calculated table is as following. My sample pbix file has been updated.

 

Expanded DrTasks = 
GENERATE(
    DrTasks,
    ADDCOLUMNS(
        GENERATESERIES(0, DrTasks[DurationMin] - 1, 1),
        "ExpandedDateTime", DrTasks[AppointmentDateTime] + TIME(0, [Value], 0),
        "DurationMinExpanded", 1
    )
)

 

amustafa_0-1707896222285.png

 





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
amustafa
Solution Sage
Solution Sage

Alright, DAX calculated table is as following. My sample pbix file has been updated.

 

Expanded DrTasks = 
GENERATE(
    DrTasks,
    ADDCOLUMNS(
        GENERATESERIES(0, DrTasks[DurationMin] - 1, 1),
        "ExpandedDateTime", DrTasks[AppointmentDateTime] + TIME(0, [Value], 0),
        "DurationMinExpanded", 1
    )
)

 

amustafa_0-1707896222285.png

 





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

Proud to be a Super User!




Works perfectly
Thanks @amustafa for your time and support.

Jramirej
Regular Visitor

Hi @amustafa 
It is working in Power Query. Thanks for the code. 

But I have a direct query table, so I can't do the transformation at the Power Query level. For that reason, I am looking for DAX Code

amustafa
Solution Sage
Solution Sage

I can only do this in Power Query. Here' my M Code. Adjust the source and column names.

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\aliom\OneDrive\Power BI Samples\Dr Appt Schedule\Sample.xlsx"), null, true),
    Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
    #"Renamed Columns" = Table.RenameColumns(Table1_Table,{{"Appointment Date & Time", "AppointmentDateTime"}, {"Duration (Mins)", "DurationMin"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Task", type text}, {"AppointmentDateTime", type datetime}, {"DurationMin", Int64.Type}}),
    
    // Custom function to generate a list of datetime values
    GenerateDateTimeList = (startDateTime as datetime, duration as number) as list =>
        List.Transform({0..duration-1}, each startDateTime + #duration(0, 0, _, 0)),

    // Apply the custom function to each row
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Time List", each GenerateDateTimeList([AppointmentDateTime], [DurationMin])),

    // Expand the custom column to new rows
    #"Expanded Time List" = Table.ExpandListColumn(#"Added Custom", "Time List"),
    
    // Optionally, adjust the final column types
    #"Final Types" = Table.TransformColumnTypes(#"Expanded Time List",{{"Time List", type datetime}}),
    #"Added Custom1" = Table.AddColumn(#"Final Types", "Duration in Mins", each 1),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Duration in Mins", Int64.Type}})
in
    #"Changed Type1"

 

amustafa_0-1707851014809.png

 

Download my sample files:

Dr Appt Schedule

 

If I answered your question, please mark this thread as accepted and Thums Up!
Follow me on LinkedIn:
https://www.linkedin.com/in/mustafa-ali-70133451/





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

Proud to be a Super User!




Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.