Showing results for 
Search instead for 
Did you mean: 
Helper II
Helper II

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 II
Helper II

@Bifinity_75 @v-polly-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


2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.