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
sauravguha
Helper I
Helper I

Power query date consolidation

Hello I have a question if Power Query can help. I have a list of names with different Start and End dates columns with different leave types. Dates may be in continuation but in different rows. i need Power query to club the dates as 1-20 March in one row and 23-26 march in another row as Annual leave and sick leave remains as is in a separate row. Possible?

Name Start Date End Date Leave Type

Mr. Smith 01-Mar-20 05-Mar-20 Annual Leave Mr. Smith 06-Mar-20 09-Mar-20 Annual Leave Mr. Smith 29-Mar-20 31-Mar-20 Sick Leave Mr. Smith 10-Mar-20 20-Mar-20 Annual Leave Mr. Smith 23-Mar-20 26-Mar-20 Annual Leave

result expected:

Mr. Smith 01-Mar-20 20-Mar-20 Annual Leave Mr. Smith 23-Mar-20 26-Mar-20 Annual Leave Mr. Smith 29-Mar-20 31-Mar-20 Sick Leave

The list has many names and may or may not have similar breakdown of leaves. For eg Mr. Dan could have only one Annual leave from 1-30 March... Thank you
1 ACCEPTED SOLUTION

@sauravguha , shared solution in PM. Created start date and end dates based on the continuous streak

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

9 REPLIES 9
parry2k
Super User
Super User

@sauravguha can you post the data in table format and expected output, it is very hard to read the blurb of data. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Sure, here you go...

 

NamePropertyDate FromDate ToLeave Type
SmithABC2020-04-012020-04-05AL
SmithABC2020-04-062020-04-16AL
SmithABC2020-04-172020-04-30SL
SmithABC2020-03-262020-03-28SL
DavidBCD2020-03-262020-03-28AL
DavidBCD2020-04-282020-04-30AL
DavidBCD2020-03-122020-03-12SL
MontyBCD2020-04-172020-04-30AL
MontyBCD2020-04-012020-04-09AL
SidABC2020-03-102020-03-10AL
SidABC2020-03-112020-03-11AL
SidABC2020-03-152020-03-15AL
SidABC2020-03-192020-03-24SL
SidABC2020-03-252020-03-31SL
SidABC2020-04-012020-04-05AL

 

Expected Result:

 

NamePropertyDate FromDate ToLeave Type
SmithABC26/03/202028/03/2020SL
SmithABC01/04/202016/04/2020AL
SmithABC17/04/202030/04/2020SL
DavidBCD12/03/202012/03/2020SL
DavidBCD01/04/202009/04/2020AL
DavidBCD17/04/202030/04/2020AL
SidABC10/03/202015/03/2020AL
SidABC19/03/202031/03/2020SL
SidABC01/04/202005/04/2020AL

Any luck Sir?

Hi, @sauravguha 

Here  is demo.

If help ,try follow steps:

1.Add custom as below  and expend the list:

=List.Dates([Date From],Duration.Days([Date To]-[Date From])+1,#duration(1,0,0,0))

36.png

 

2. Remove two column "Date From "  and  "Date to"
3. Then group rows as below

37.png

 

3.Add custom colum "split"as below

=Table.Group(let a = [Data]
in
Table.AddColumn(a, "New"
,each 
  let d = [Date],
  t = Table.AddColumn(
      Table.SelectRows(a, each [Date] <=d),"Temp", each Duration.Days(d-[Date])
      )
  in 
     Table.Min(Table.SelectRows(t, each [Temp] <=Table.RowCount(t)),"Date")[Date]), {"New"}, {{"Date To", each List.Max([Date]), type date}})

4.Then remove the  column "Data " and expand the column "Split"

 

If I misunderstood your request, please explain more about your calculation logic.

And  I am afraid the excepted result you attached is a bit wrong, as i dont see anywhere Monty's record.

 

Best Regards,
Community Support Team _ Eason

Hello   Thanks for taking time to attend to my query.   I have only one issue. If i have a date range like 26 Mar - 30 Mar 2020 and another one from 1 Apr - 30 Apr 2020, the query is merging it to show 26 Mar - 30 April 2020 when it should remain same since 31st March 2020 is missing in between.   How can we sort this small issue?   Thanks again.   Saurav

Hi , @sauravguha 

Not very clear .It is recommended to open another thread to explain your  additional problem in more detail.

Best Regards,
Community Support Team _ Eason

Hi, thanks for your assistance and sorry for not being able to clarify as needed. Below is a new example where i believe i would be able to explain more. 

 

In the first 2 names, Prasanna, since he has two sets of leave dates which are not in continuation, expected result is same as Given data. However, on the name "Said", his first 2 leaves are in continuation, hence, expected result is a date range combining the same and making one and his 3rd date range is kept in a separate row since it is not in continuation with the first two date ranges. 

 

Was i able to make it clearer? Thank you again for assisting. 

 

 Given Data     Expected result  
Emp IDNameStart DateEnd DateLeave Type Emp IDNameStart DateEnd DateLeave Type
E1545Prasanna23-Mar-2030-Mar-20AL E1545Prasanna23-Mar-2030-Mar-20AL
E1545Prasanna01-Apr-2030-Apr-20AL E1545Prasanna01-Apr-2030-Apr-20AL
E116460Said 10-Mar-2016-Mar-20SL E116460Said 10-Mar-2019-Mar-20SL
E116460Said 17-Mar-2019-Mar-20SL E116460Said 28-Apr-2030-Apr-20SL
E116460Said 28-Apr-2030-Apr-20SL E115838Suraj 31-Mar-2006-Apr-20AL
E115838Suraj 31-Mar-2006-Apr-20AL E115838Suraj 11-Apr-2015-Apr-20AL
E115838Suraj 11-Apr-2015-Apr-20AL E18433Manikandan22-Mar-2015-Apr-20AL
E18433Manikandan22-Mar-2028-Mar-20AL E116043George22-Mar-2023-Apr-20SL
E18433Manikandan29-Mar-2015-Apr-20AL E115882Permeshwar 26-Mar-2030-Mar-20AL
E116043George22-Mar-2006-Apr-20SL E115882Permeshwar 01-Apr-2030-Apr-20AL
E116043George07-Apr-2015-Apr-20SL E115587Illeperumage18-Mar-2019-Mar-20AL
E116043George16-Apr-2023-Apr-20SL E115587Illeperumage23-Mar-2026-Mar-20AL
E115882Permeshwar 26-Mar-2030-Mar-20AL E115587Illeperumage17-Apr-2030-Apr-20AL
E115882Permeshwar 01-Apr-2030-Apr-20AL E117332Hosny01-Mar-2011-Mar-20SL
E115587Illeperumage18-Mar-2019-Mar-20AL E117332Hosny26-Mar-2030-Apr-20AL
E115587Illeperumage23-Mar-2026-Mar-20AL      
E115587Illeperumage17-Apr-2030-Apr-20AL      
E117332Hosny01-Mar-2001-Mar-20SL      
E117332Hosny02-Mar-2002-Mar-20SL      
E117332Hosny03-Mar-2003-Mar-20SL      
E117332Hosny04-Mar-2004-Mar-20SL      
E117332Hosny05-Mar-2005-Mar-20SL      
E117332Hosny06-Mar-2006-Mar-20SL      
E117332Hosny07-Mar-2007-Mar-20SL      
E117332Hosny08-Mar-2008-Mar-20SL      
E117332Hosny09-Mar-2009-Mar-20SL      
E117332Hosny10-Mar-2010-Mar-20SL      
E117332Hosny11-Mar-2011-Mar-20SL      
E117332Hosny26-Mar-2016-Apr-20AL      
E117332Hosny17-Apr-2024-Apr-20AL      
E117332Hosny25-Apr-2030-Apr-20AL      

@sauravguha , shared solution in PM. Created start date and end dates based on the continuous streak

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you so much for the assistance, it works very well. will try on a live data and let you know if i face any challenge.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors