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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.