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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Navaneetharaju_
Helper II
Helper II

Next_run_dates based on the occurrences

Hi , 

 

This request regards the task report, finding the next_run_date and time for task based on the repeat_every, and end_occurences ,


Task_name = Task 1
utc_start_date = 27-Feb-24
utc_start_time = 03:00:00 PM
Repeat_every = 15

Repeat_by = minutes 

End_Occurences = 2000


I have created the series in power query
Series = {1..[End_Occurences]
It's created the 2000 rows for the one task and i have added the query function to create the next_run_times based on the occurences and repeat every field
next_run_time = [utc_start_time]+#duration(0,0,[repeat_every]*[Series],0)

I'm getting the results of every 15 mins of time like, 03:00:00 PM, 03:15:00 PM, 03:30:00 PM till the end occurrences count the times are repeating.
I want to find the next_run_dates using power query,
Because task_start_date (27-FEB-2024) and start_time (03:00:00 PM) it's running from the time onwards,  after the 23:59:59 the the tasks will running on 28-Feb-2024 .

need to find the next dates column along with the next_run_time

scenario:
If select 27 th feb in my slicer it should show count of the task which runs on that day,  if i select 28th feb 24 it should show only the count of task will run on that.

Please help me to get this done 

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

I am not 100% sure this is what you are looking for. But it might get you pointed in the right direction.
If you are looking for a result similar to...

jgeddes_0-1709049805774.png

I was able to achieve this with the following code...

let
    Source = 
    Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkkszlYwVNJRMjDSNzLXNzIwMgFyDE2tDAzANJDIzcwrLUktBrKMDICisbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Task_name = _t, utc_start_date = _t, utc_start_time = _t, Repeat_every = _t, Repeat_by = _t, End_Occurences = _t]),
    #"Changed Type" = 
    Table.TransformColumnTypes(
        Source,
        {
            {"Task_name", type text}, 
            {"utc_start_date", type date}, 
            {"utc_start_time", type time}, 
            {"Repeat_every", Int64.Type}, 
            {"Repeat_by", type text}, 
            {"End_Occurences", Int64.Type}
        }
    ),
    #"Inserted Merged Column" = 
    Table.AddColumn(
        #"Changed Type", 
        "utc_start_datetime", 
        each 
        DateTime.From(
            Text.Combine(
                {
                    Text.From([utc_start_date], "en-US"), 
                    Text.From([utc_start_time], "en-US")
                },
                " "
            )
        ), 
        type datetime
    ),
    #"Added Custom" = 
    Table.AddColumn(
        #"Inserted Merged Column", 
        "Repeat_duration", 
        each 
        if [Repeat_by] = "days" 
            then #duration([Repeat_every], 0, 0, 0) 
            else 
        if [Repeat_by] = "hours" 
            then #duration(0, [Repeat_every], 0, 0) 
            else 
        if [Repeat_by] = "minutes" 
            then #duration(0, 0, [Repeat_every], 0) 
            else #duration(0, 0, 0, [Repeat_every]), 
        type duration
    ),
    Custom1 = 
    Table.AddColumn(
        #"Added Custom", 
        "_seriesTable", 
        each 
        List.DateTimes([utc_start_datetime], [End_Occurences], [Repeat_duration]), 
        type list
    ),
    #"Removed Columns" = 
    Table.RemoveColumns(
        Custom1,
        {"utc_start_date", "utc_start_time", "Repeat_every", "Repeat_by", "End_Occurences", "utc_start_datetime", "Repeat_duration"}
    ),
    #"Expanded _seriesTable" = 
    Table.ExpandListColumn(
        #"Removed Columns", 
        "_seriesTable"
    ),
    #"Inserted Date" = 
    Table.AddColumn(
        #"Expanded _seriesTable", 
        "Occurence_date", 
        each DateTime.Date([_seriesTable]), 
        type date
    )
in
    #"Inserted Date"



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

Proud to be a Super User!





View solution in original post

2 REPLIES 2
jgeddes
Super User
Super User

I am not 100% sure this is what you are looking for. But it might get you pointed in the right direction.
If you are looking for a result similar to...

jgeddes_0-1709049805774.png

I was able to achieve this with the following code...

let
    Source = 
    Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkkszlYwVNJRMjDSNzLXNzIwMgFyDE2tDAzANJDIzcwrLUktBrKMDICisbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Task_name = _t, utc_start_date = _t, utc_start_time = _t, Repeat_every = _t, Repeat_by = _t, End_Occurences = _t]),
    #"Changed Type" = 
    Table.TransformColumnTypes(
        Source,
        {
            {"Task_name", type text}, 
            {"utc_start_date", type date}, 
            {"utc_start_time", type time}, 
            {"Repeat_every", Int64.Type}, 
            {"Repeat_by", type text}, 
            {"End_Occurences", Int64.Type}
        }
    ),
    #"Inserted Merged Column" = 
    Table.AddColumn(
        #"Changed Type", 
        "utc_start_datetime", 
        each 
        DateTime.From(
            Text.Combine(
                {
                    Text.From([utc_start_date], "en-US"), 
                    Text.From([utc_start_time], "en-US")
                },
                " "
            )
        ), 
        type datetime
    ),
    #"Added Custom" = 
    Table.AddColumn(
        #"Inserted Merged Column", 
        "Repeat_duration", 
        each 
        if [Repeat_by] = "days" 
            then #duration([Repeat_every], 0, 0, 0) 
            else 
        if [Repeat_by] = "hours" 
            then #duration(0, [Repeat_every], 0, 0) 
            else 
        if [Repeat_by] = "minutes" 
            then #duration(0, 0, [Repeat_every], 0) 
            else #duration(0, 0, 0, [Repeat_every]), 
        type duration
    ),
    Custom1 = 
    Table.AddColumn(
        #"Added Custom", 
        "_seriesTable", 
        each 
        List.DateTimes([utc_start_datetime], [End_Occurences], [Repeat_duration]), 
        type list
    ),
    #"Removed Columns" = 
    Table.RemoveColumns(
        Custom1,
        {"utc_start_date", "utc_start_time", "Repeat_every", "Repeat_by", "End_Occurences", "utc_start_datetime", "Repeat_duration"}
    ),
    #"Expanded _seriesTable" = 
    Table.ExpandListColumn(
        #"Removed Columns", 
        "_seriesTable"
    ),
    #"Inserted Date" = 
    Table.AddColumn(
        #"Expanded _seriesTable", 
        "Occurence_date", 
        each DateTime.Date([_seriesTable]), 
        type date
    )
in
    #"Inserted Date"



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

Proud to be a Super User!





Hi @jgeddes , 
It's working as expected. Thank you for your response.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors