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
RicLup
Helper III
Helper III

New row Values between end date and new start date

Hi guys;

I would like you can help me, I need to identify the DateDiff in days between end date and new start date in some assignation employee, so if the difference is >1 add the register for each day with difference with status Free.

 

Example:

Original Table:

 

Original Table.PNG

 

My result must to be like this:

 

Result Table.PNG

 

Is it possible add new row for each difference day like table above?

 

Regards and thanks for your time.

 

1 ACCEPTED SOLUTION

Hi @RicLup ,

 

Please try to use the following custom column forumla, sample is in Query 4 and Query 5 of file:

 

let 
  i = [IS],  sd = [StartDate],  ed = [EndDate],
  td = DateTime.Date(DateTimeZone.UtcNow()),
  OneDay = #duration(1,0,0,0),

  MaxDay = Table.Max(Table.SelectRows(Assignment,each [IS] = i),"EndDate")[#"EndDate"],
  temp = Table.SelectRows(Assignment,each [IS] = i and [EndDate]>ed ),

  NextStartDay = if Table.RowCount(temp)=0 then null else Table.Min(temp,"StartDate")[#"StartDate"],
  
  Assigned = if [StartDate] = [EndDate] 
		then Table.AddColumn(Table.SelectColumns(Table.FromRecords({_}),{"StartDate","EndDate"}),"unassignmentStatus",each "One Day Assignation")
		else Table.SelectColumns(Table.FromRecords({_}),{"StartDate","EndDate","unassignmentStatus"}),

  Hisotoric = Table.AddColumn(Table.AddColumn(
            Table.RenameColumns(
                Table.FromList(List.Dates(sd+OneDay,Duration.Days(ed-sd),OneDay)
                    , Splitter.SplitByNothing()
                    , null, null, ExtraValues.Error)
           ,{"Column1","StartDate"})
        ,"EndDate",each [StartDate])
        ,"unassignmentStatus",each "Assigned Historic Register"),

  Pool = Table.AddColumn(Table.AddColumn(
            Table.RenameColumns(
                Table.FromList(List.Dates(ed+OneDay,Duration.Days(NextStartDay-OneDay-ed),OneDay)
                    , Splitter.SplitByNothing()
                    , null, null, ExtraValues.Error)
           ,{{"Column1", "StartDate"}})
        , "EndDate", each [StartDate])
        , "unassignmentStatus", each "Difference End Date and New Start Date")

in 
  if  sd = ed and ed < td and ed = MaxDay
  then Table.Combine({Assigned,Table.AddColumn(Table.AddColumn(Table.RenameColumns(Table.FromList(List.Dates(ed+OneDay,Duration.Days(td-ed),OneDay), Splitter.SplitByNothing(), null, null, ExtraValues.Error),{"Column1","StartDate"}),"EndDate",each [StartDate]),"unassignmentStatus",each "Last End Date Register until Today")})
  else if sd = ed
  then   Table.Combine({Assigned,Pool})
else
  if ed = MaxDay and ed < td
  then 
    Table.Combine({Assigned,Hisotoric,Table.AddColumn(Table.AddColumn(Table.RenameColumns(Table.FromList(List.Dates(ed+OneDay,Duration.Days(td-ed),OneDay), Splitter.SplitByNothing(), null, null, ExtraValues.Error),{"Column1","StartDate"}),"EndDate",each [StartDate]),"unassignmentStatus",each "Last End Date Register until Today")})
  else 
    if NextStartDay = null or NextStartDay - ed = OneDay or NextStartDay < ed
    then 
        Table.Combine({Assigned,Hisotoric})
    else 
        Table.Combine({Assigned,Hisotoric,Pool})

 


By the way, PBIX file as attached.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

20 REPLIES 20

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.