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
sam_gift
Helper I
Helper I

Date Difference between snapshots based on a column

Hi, Please help with the dax for below.

sam_gift_1-1724113155100.png

I have a sample data here. I need to compare the date for the same ID of snapshot -1 with snapshot seq -2, and give the days different. If the date is same then 0, if not no.of days difference between the snapshots

 

For example ID A1 have the date '2/8/2024/ for -1 and /7/8/2024 for -2. so the day diff will be 151 days. similarly for B1, C1 and so on. Please help me with the dax

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1724130773281.png

 

 

Jihwan_Kim_0-1724130735917.png

 

 

expected result measure: = 
VAR _seqone = -1
VAR _seqtwo = -2
VAR _dayone =
    MAXX(
        FILTER( data, data[snapshot_seq] = _seqone ),
        data[date]
    )
VAR _daytwo =
    MAXX(
        FILTER( data, data[snapshot_seq] = _seqtwo ),
        data[date]
    )
RETURN
    IF(
        HASONEVALUE( 'id'[id] ),
        DATEDIFF( _dayone, _daytwo, DAY )
    )

 


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

AntrikshSharma
Super User
Super User

@sam_gift If you want a calculated column in your table then you can try this:

 

Column = 
VAR CurrentSnapshotSeq = 
    Sam[SnapshotSeq]
VAR CurrentDate = 
    Sam[Date]
VAR PreviousDate = 
    CALCULATE ( 
        MIN ( Sam[Date] ),
        Sam[SnapshotSeq] > CurrentSnapshotSeq,
        ALLEXCEPT ( Sam, Sam[ID] )
    )
VAR Result = 
    IF ( 
        PreviousDate,
        INT ( CurrentDate - PreviousDate )
    )
RETURN Result

 

AntrikshSharma_0-1724133402920.png

 

For a measure in a visual you can change it a little bit:

 

AntrikshSharma_1-1724133439366.png

 

 

View solution in original post

2 REPLIES 2
AntrikshSharma
Super User
Super User

@sam_gift If you want a calculated column in your table then you can try this:

 

Column = 
VAR CurrentSnapshotSeq = 
    Sam[SnapshotSeq]
VAR CurrentDate = 
    Sam[Date]
VAR PreviousDate = 
    CALCULATE ( 
        MIN ( Sam[Date] ),
        Sam[SnapshotSeq] > CurrentSnapshotSeq,
        ALLEXCEPT ( Sam, Sam[ID] )
    )
VAR Result = 
    IF ( 
        PreviousDate,
        INT ( CurrentDate - PreviousDate )
    )
RETURN Result

 

AntrikshSharma_0-1724133402920.png

 

For a measure in a visual you can change it a little bit:

 

AntrikshSharma_1-1724133439366.png

 

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1724130773281.png

 

 

Jihwan_Kim_0-1724130735917.png

 

 

expected result measure: = 
VAR _seqone = -1
VAR _seqtwo = -2
VAR _dayone =
    MAXX(
        FILTER( data, data[snapshot_seq] = _seqone ),
        data[date]
    )
VAR _daytwo =
    MAXX(
        FILTER( data, data[snapshot_seq] = _seqtwo ),
        data[date]
    )
RETURN
    IF(
        HASONEVALUE( 'id'[id] ),
        DATEDIFF( _dayone, _daytwo, DAY )
    )

 


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.

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.