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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply

Max interval of days between two dates on date column

Hi guys,

 

I'm trying to calculate the interval of days between a date value and the last date before that date (doing this to all dates in column), and then show the max value of these intervals.

 

For example:

1. calculate the date intervals between the dates on column:

filipeoliveira_1-1647264937232.png

 

2. and then return the max value from the intervals calculated above (6 days), in a measure.

 

Some idea?

 

Appreciate any help.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I added two more rows in the sample in order to check if it works correctly.

 

Picture1.png

 

Expected result measure: =
VAR newtable =
    ADDCOLUMNS (
        Data,
        "@previous",
            CALCULATE (
                CALCULATE (
                    MAX ( Data[DataRef] ),
                    FILTER (
                        ALL ( Data ),
                        Data[DataRef] < VAR currentdataref = MAX ( Data[DataRef] ) RETURN currentdataref
                    )
                )
            )
    )
VAR intervaltable =
    FILTER (
        ADDCOLUMNS ( newtable, "@interval", INT ( Data[DataRef] - [@previous] ) ),
        [@previous] <> BLANK ()
    )
VAR maximuminterval =
    MAXX ( intervaltable, [@interval] )
RETURN
    maximuminterval

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I added two more rows in the sample in order to check if it works correctly.

 

Picture1.png

 

Expected result measure: =
VAR newtable =
    ADDCOLUMNS (
        Data,
        "@previous",
            CALCULATE (
                CALCULATE (
                    MAX ( Data[DataRef] ),
                    FILTER (
                        ALL ( Data ),
                        Data[DataRef] < VAR currentdataref = MAX ( Data[DataRef] ) RETURN currentdataref
                    )
                )
            )
    )
VAR intervaltable =
    FILTER (
        ADDCOLUMNS ( newtable, "@interval", INT ( Data[DataRef] - [@previous] ) ),
        [@previous] <> BLANK ()
    )
VAR maximuminterval =
    MAXX ( intervaltable, [@interval] )
RETURN
    maximuminterval

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thanks! It worked for me.

amitchandak
Super User
Super User

@filipeoliveira , A new column

 

datediff([Dateref], minx(filter(Table, [Dateref] >earlier([Dateref]) ), [DateRef]) , Day)

 

or

 

datediff([Dateref], maxx(filter(Table, [Dateref] <earlier([Dateref]) ), [DateRef]) , Day)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.