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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
mayurbajaj
New Member

Finding Gaps Between the dates

Data Table

SiteMeterIdentifier

Account Number

Invoice Start Date

Invoice End Date

1

2

01/11/2023

30/11/2023

1

2

01/01/2024

31/01/2024

1

2

01/03/2024

31/03/2024

1

2

01/04/2024

30/04/2024

 

Expected Output

SiteMeterIdentifier

Account Number

Invoice Start Date

Invoice End Date

1

2

01/04/2024

30/04/2024

1

2

01/02/2024

29/02/2024

 

Can this be managed through a DAX Measure?

1 ACCEPTED SOLUTION
aduguid
Super User
Super User

aduguid_0-1716527608837.png

Create the following calculated columns

 

Next Invoice Start Date = 
CALCULATE(
    MIN(Invoice[Invoice Start Date]),
    FILTER(
        Invoice,
        Invoice[Account Number] = EARLIER(Invoice[Account Number]) &&
        Invoice[SiteMeterIdentifier] = EARLIER(Invoice[SiteMeterIdentifier]) &&
        Invoice[Invoice Start Date] > EARLIER(Invoice[Invoice Start Date])
    )
)

 

 

Gap Start Date = 
IF(
    ISBLANK(Invoice[Next Invoice Start Date]),
    BLANK(),
    IF(
        DATEDIFF(Invoice[Invoice End Date], Invoice[Next Invoice Start Date], DAY) > 1,
        Invoice[Invoice End Date] + 1,
        BLANK()
    )
)

 

 

Gap End Date = 
IF(
    ISBLANK(Invoice[Next Invoice Start Date]),
    BLANK(),
    IF(
        DATEDIFF(Invoice[Invoice End Date], Invoice[Next Invoice Start Date], DAY) > 1,
        Invoice[Next Invoice Start Date] - 1,
        BLANK()
    )
)

 

View solution in original post

2 REPLIES 2
aduguid
Super User
Super User

aduguid_0-1716527608837.png

Create the following calculated columns

 

Next Invoice Start Date = 
CALCULATE(
    MIN(Invoice[Invoice Start Date]),
    FILTER(
        Invoice,
        Invoice[Account Number] = EARLIER(Invoice[Account Number]) &&
        Invoice[SiteMeterIdentifier] = EARLIER(Invoice[SiteMeterIdentifier]) &&
        Invoice[Invoice Start Date] > EARLIER(Invoice[Invoice Start Date])
    )
)

 

 

Gap Start Date = 
IF(
    ISBLANK(Invoice[Next Invoice Start Date]),
    BLANK(),
    IF(
        DATEDIFF(Invoice[Invoice End Date], Invoice[Next Invoice Start Date], DAY) > 1,
        Invoice[Invoice End Date] + 1,
        BLANK()
    )
)

 

 

Gap End Date = 
IF(
    ISBLANK(Invoice[Next Invoice Start Date]),
    BLANK(),
    IF(
        DATEDIFF(Invoice[Invoice End Date], Invoice[Next Invoice Start Date], DAY) > 1,
        Invoice[Next Invoice Start Date] - 1,
        BLANK()
    )
)

 

mayurbajaj
New Member

Expected Output

Expected Output

SiteMeterIdentifier

Account Number

Invoice Start Date

Invoice End Date

1

2

01/12/2023

31/12/2023

1

2

01/02/2024

29/02/2024

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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