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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Helper III
Helper III

Determining Gaps between Dates



I am trying to determine start and end dates of a range that act as a "gap" between when a room is occupied.  So, a room would be occupied from a start to an end date.  However, after the end date comes and goes, there is now a gap between when that room was and will be occupied.  Here's what it looks like in Excel.  My end result is that I want the start and end dates for the gap so that it can then be mapped in a Gantt Chart:


The Gap Start begins one day after the End date and the Gap End date ends one day prior to the next occupation of that room. 


Thank you for your help!


Helper III
Helper III

@Bifinity_75 @v-rongtiep-msft Thank you for your responses.  After diving deeper into my data, it turns out there are some other factors to consider.  Initially, I wasn't aware that a room could be occupied by more than one item at a time so some of the calculations based on "EARLIER" or utilzing the Index column in Power Query were resulting in some incorrect dates.  Here's a better indication of what I'm working with:


As you can see, some of the blue bars overlap and they are in the same room at the same time.  The green highlights are the gaps in the rooms for this time period that I'd like to be able to show. The point of all of this is for an individual to be able to look at a Gantt chart and say "OK, this room is available from this date to this date".  
Another consideration:
 - A gap of only one day is irrelevant so it would not need to show up on the Gantt

Hopefully this helps and I really do appreciate your effort here! 



Solution Sage
Solution Sage

Hi @JLambs20, is the "name" of the step to insert the index column:


Usually the name is 'Addex Index', but if you have another language, the name will be different. If you change it, it should work for you.

Best regards

Community Support
Community Support

Hi @JLambs20 ,

I have created a simple smaple, please refer to it to see if it helps you.

Add an index column in the Power Query.

Then add two custom columns.

=Date.AddDays([End], 1)
=try Date.AddDays(Table.SelectRows(#"Added Custom",(x)=>x[Index]=[Index]+1)[start]{0},-1) otherwise ""


I have also create columns use dax.

gap end = var _next=CALCULATE(MAX('Table'[start]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])+1))
gap start = 'Table'[End]+1


If I have misunderstood your meaning, please provide more details with your desired output and pbix file without privacy information.


Best Regards

Community Support Team _ Polly


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.


Solution Sage
Solution Sage

Hi @JLambs20 , try this:

1º.- in Power Query, create a Index Column:



2º.- Create a custom column (Name: Gap Start) with this function:


3º.- Create a custom column (Name: End start) with this function:

try Date.AddDays(#'Added Index' [Start] {[Index]+1},-1) otherwise ""

4º- The result:



Best regards


Thanks for the feedback! I'm having one issue with that last equation you wrote. The sytax for #'Added Index' doesn't seem to work.  It's saying there should be a token literal in there somewhere.  What am I missing? 



Resolver II
Resolver II



I have seen a solution to this before at the below link:


Just make sure you note there are two parts to the answer in different replies. The first requires you to use M Code to make a partition index by room number. 

Then the second creates two calculated columns, one for previous date end, and one for the date diff.


Good luck

Helpful resources

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.