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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

DATEDIFF Difference from two different rows and column

Hello everyone,

I  have a table like below-

 

property_idContract_idstart_dateend_dateState
100100.0315.04.2019 Confirmed
100100.0201.01.201530.09.2018Expired
100100.0115.02.201031.09.2017Expired

 

Now I need to find how long the apartment was vacant. Since the property_id is same for both the rows, it is the same apartment and end_date(100.01) minus start_date(100.02) gives me the duration for which this apartment was vacant. Which is in this case equals 197 days.

 

Could someone please help me to find this. I created a rank column using below DAX whic give me 1 for the first row and 2 for the next row in this example.

 

Ranks Col = RANKX (
FILTER ( 'table', 'table'[property_id] = EARLIER ('table'[property_id] ) ),
'table'[start_date],
,
DESC,
DENSE
)
1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous ,

Are there always two rows per property?

If so you can create a new calculated column:

NewCol =
VAR  _Date1 = CALCULATE(MIN(Table1[end_date]), Table1[end_date]<> BLANK() ,ALLEXCEPT(Table1, Table1[property_id]))
VAR  _Date2 = CALCULATE(MAX(Table1[start_date]), ALLEXCEPT(Table1, Table1[property_id]))
RETURN
_Date2 - _Date1

 

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @Anonymous ,

Are there always two rows per property?

If so you can create a new calculated column:

NewCol =
VAR  _Date1 = CALCULATE(MIN(Table1[end_date]), Table1[end_date]<> BLANK() ,ALLEXCEPT(Table1, Table1[property_id]))
VAR  _Date2 = CALCULATE(MAX(Table1[start_date]), ALLEXCEPT(Table1, Table1[property_id]))
RETURN
_Date2 - _Date1

 

Anonymous
Not applicable

Hi @AlB ,

 

Thank you for your response. I will give it a try.

 

And regarding your question, No it could be more than two rows and even one row only as well (if there is only one contract till now for that apartment).

 

Best,

Ashu

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.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors