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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
JLambs20
Helper III
Helper III

Determining Gaps between Dates

Hello,

 

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:

JLambs20_0-1668026494301.png

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!

 

6 REPLIES 6
JLambs20
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:

JLambs20_0-1668089440710.png

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! 

 

Regards



Bifinity_75
Solution Sage
Solution Sage

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

Bifinity_75_0-1668080766044.png

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

v-rongtiep-msft
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 ""

vpollymsft_0-1668062439890.png

I have also create columns use dax.

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

vpollymsft_1-1668062503467.png

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.

 

Bifinity_75
Solution Sage
Solution Sage

Hi @JLambs20 , try this:

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

Bifinity_75_1-1668031685566.png

 

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

Date.AddDays([End],1)

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

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

4º- The result:

Bifinity_75_0-1668031574161.png

 

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? 

JLambs20_0-1668032721218.png

 

MDodds
Resolver II
Resolver II

Hello,

 

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

https://community.powerbi.com/t5/Desktop/Date-difference-between-clients-current-and-previous-row/m-...

 

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

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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