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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

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
Super User
Super User

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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