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
ClemFandango
Advocate II
Advocate II

How to calculate days between gaps in continuous dates?

Hello wonderful PowerBI community!


First off, apologies that the data is difficult to read, so i have copied both a screenshot and data table of the same data to help illustrate. I have spent hours reading every help post I can find, but the table continually loses its formatting. I am also unable to upload my PBix. Anyway here is my real issue...


I am trying to find the gaps between continuous dates and then calculate the number of days (for specific references as per Ref column) for how long there was a gap between a continuous date. This may or may not be complicated by some of the start & end dates overlapping.


My data is as per below - I am hoping to calculate the gaps by adding the last 3 calculated columns. The columns are blank where there is a continuous date and no prior end date (to the continuous date). Any ideas in how I can get these 3 calculated columns to work?

 

End Date Prior to continuous dates = the end date of the previous block of continuous dates (for each Ref)

Earliest Start Date of continuous dates = the min start date where there is a date for 'End Date Prior to continuous dates' (for each Ref)

Days between Start&End = differeance between 'End Date Prior to continuous dates' & 'Earliest Start Date of continuous dates' in days

 

ClemFandango_0-1683096919656.png

 

 

RefEnd DateStart DateEnd Date prior to continous datesEarliest Start Date of continuous datesDays between Start&End
12630/04/202428/03/202330/04/202228/03/2023332
12630/04/202428/03/202330/04/202228/03/2023332
12630/04/202130/04/2020   
12629/04/201901/01/2018   
12630/04/202030/04/2019   
12630/04/202230/04/2021   
17431/10/202131/10/2020   
17431/10/201901/11/2018   
17431/10/202031/10/2019   
17431/10/202308/08/202231/10/202108/08/2022281
17431/10/202308/08/202231/10/202108/08/2022281
17431/10/202131/10/2020   
17401/11/202031/05/2019   
17430/05/201901/01/2018   
37630/04/202130/04/2020   
37629/04/201901/01/2018   
37630/04/202030/04/2019   
37630/09/202330/09/202230/04/202101/02/2022277
37630/09/202330/09/202230/04/202101/02/2022277
37630/09/202201/02/202230/04/202101/02/2022277
37630/09/202201/02/202230/04/202101/02/2022277
142129/02/202428/02/2023   
142131/03/202431/03/2023   
142129/02/202428/02/2023   
142131/03/202431/03/2023   
142129/02/202428/02/2023   
142131/03/202431/03/2023   
142131/03/202130/06/2019   
142131/03/202231/03/2021   
142131/03/202331/03/2022   
142131/03/202131/03/2020   
142131/03/202031/03/2019   
142131/03/202231/03/2021   
142131/03/202031/03/2019   
142131/03/202331/03/2022   
142131/03/202131/03/2020   
142131/03/202231/03/2021   
142131/03/202031/03/2019   
142131/03/202331/03/2022   
142131/03/201901/01/2018   
142131/03/201901/01/2018   
142129/06/201901/01/2018   
1 ACCEPTED SOLUTION
Wilson_
Super User
Super User

Hello ClemFandango,

 

Try the below for your calculated columns:

End Date Prior to Continuous Dates = 
VAR Ref = 'Table'[Ref]
VAR StartDate = 'Table'[Start Date]
VAR Filtered =
FILTER (
    'Table',
    'Table'[Ref] = Ref &&
    'Table'[End Date] <= StartDate
)

VAR Result =
MAXX (
    Filtered,
    'Table'[End Date]
)

RETURN IF ( StartDate - Result > 1, Result )
Earliest Start Date of Continuous Dates = 
IF (
    NOT ( ISBLANK ( 'Table'[End Date Prior to Continuous Dates] ) ),
    'Table'[Start Date]
)
Days Between Start&End = 'Table'[Earliest Start Date of Continuous Dates] - 'Table'[End Date Prior to Continuous Dates]


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

6 REPLIES 6
ClemFandango
Advocate II
Advocate II

Hi @Wilson_ thanks again for this. I sovled this by adding a couple of extra conditions to reduce the false positivies that resulted from the overlapping dates.

Very cool, glad you figured it out. 😄

 

I meant to take another look at this but never got around to it hah.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





ClemFandango
Advocate II
Advocate II

Hi @Wilson_ 

Apologies, i thought i marked this as a solution already:-

 

Just another question, i have just found an issue with my logic. I am trying to return the start & end date where there is a break with a non-continuous date. Your calculated column works well in the vast majority of cases, however where the 'Start Date' & 'End Date' overlap previously existing dates, it will falsely report a break in continuous dates.

 

Please see example of the issue below. Do you have any ideas how I can tweak your amazing calculated column to ignore situations like this? Ideally this will show no Continuous Dates in the example below.

 

I have highlighted a specific date in green. The yellow dates show where it overlaps.

 

ClemFandango_0-1683206010387.png

 

(more useable version of the screenshot above)

RefStart DateEnd DateEnd Date Prior to Continuous DatesEarliest Start Date of Continuous DatesDays Between Start&End
44201/01/201829/09/2019   
44201/01/201829/09/2019   
44201/01/201829/09/2019   
44201/01/201829/09/2019   
44201/01/201829/09/2019   
44201/01/201829/09/2019   
44230/09/201930/09/2020   
44230/09/201930/09/2020   
44230/09/201930/09/2020   
44230/09/201930/09/2020   
44230/09/201930/09/2020   
44230/09/201930/09/2020   
44221/07/202030/08/202129/09/201921/07/2020296
44230/09/202030/09/2021   
44230/09/202030/09/2021   
44230/09/202030/09/2021   
44230/09/202030/09/2021   
44202/10/202030/09/202130/09/202002/10/20202
44231/08/202131/08/2022   
44230/09/202130/09/2022   
44230/09/202130/09/2022   
44230/09/202130/09/2022   
44230/09/202130/09/2022   
44230/09/202130/09/2022   
44211/10/202113/10/202130/09/202111/10/202111
44230/09/202230/09/2023   
44230/09/202230/09/2023   
44230/09/202230/09/2023   
44230/09/202230/09/2023   
44230/09/202230/09/2023   
Wilson_
Super User
Super User

Hello ClemFandango,

 

Try the below for your calculated columns:

End Date Prior to Continuous Dates = 
VAR Ref = 'Table'[Ref]
VAR StartDate = 'Table'[Start Date]
VAR Filtered =
FILTER (
    'Table',
    'Table'[Ref] = Ref &&
    'Table'[End Date] <= StartDate
)

VAR Result =
MAXX (
    Filtered,
    'Table'[End Date]
)

RETURN IF ( StartDate - Result > 1, Result )
Earliest Start Date of Continuous Dates = 
IF (
    NOT ( ISBLANK ( 'Table'[End Date Prior to Continuous Dates] ) ),
    'Table'[Start Date]
)
Days Between Start&End = 'Table'[Earliest Start Date of Continuous Dates] - 'Table'[End Date Prior to Continuous Dates]


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





@Wilson_ This is amazing! Thank you so much

Sweet, glad it worked for you!

 

Can you please mark my last response as the solution so people know this one is solved and to make the solution easier to find for anybody else who sees this post in the future? 😄




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.