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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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.

Top Solution Authors
Top Kudoed Authors