Friday, March 21, 2025

How to generate list of Dates available between Start Date and End Date using Power Query

How to create list of Dates falls between Start Date and End Date using Power Query
Scenario:
Let's say we have two date columns in a Dataset as Task_Start_Date and Task_End_Date as shown below.


Now we need to generate a new Date column as "Task_Active_Dates" based on the no. of Dates falls between Task_Start_Date and Task_End_Date.

For example, Task_Start_Date = 01-Jan-2021 and Task_End_Date= 05-Jan-2021, then there are 5 no. of dates falls between those dates (inclusive of Start and End Dates).

We can achieve this Scenario, using the below Power Query logic:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddDLCQAhDATQXnJ2IYn/WsT+23DZuYwLAS/jk4m6lqg973J1kyRaKZjs9PdGweHOPilkeI76C7xEXuE16m9wvpIphQ7v7PyYAR9R/4Tzll3/o9+Ba6aVa5rsfQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Task_Start_Date = _t, Task_End_Date = _t, Task_Owner_ID = _t]),
    
ChangeType = Table.TransformColumnTypes(Source,{{"Task_Start_Date", type date}, {"Task_End_Date", type date}, {"Task_Owner_ID", Int64.Type}}),

TaskActiveDates =
Table.AddColumn(ChangeType, "Task_Active_Dates",
    each List.Dates(
    [Task_Start_Date], 
    Duration.Days([Task_End_Date]-[Task_Start_Date])+1,
    #duration(1,0,0,0)
)),
    ExpandDates = Table.ExpandListColumn(TaskActiveDates, "Task_Active_Dates")
in
    ExpandDates

Result:

--------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Analytics Professional
--------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. If you wish, please share your genuine Feedback or comments only related to this Blog Posts. It is my humble request that, please do not post any Spam comments or Advertising kind of comments, which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose we have a sample Sales data, which is stored with Monthly Snapsh...

Popular Posts from this Blog