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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
RichOB
Post Patron
Post Patron

Need help with Day Count measure between end dates and start dates

Hi, apologies for posting similar to a previous post, but my issue remains. I have student accommodation and under each Property I need to add the Days_Empty column.

 

1 - Per each bedspace, I need the count of days between the End_Date and the Start_Date of the next tenancy.

 

2 - When there is no end date I need the Days_Empty to show as 0.

 

3 - Per Bedspce, when there is an End_Date but no one has next moved into the bedspace, I need the Days_Empty count to be from the End_Date entered to Today's date. When someone moves into the bedspace and there is a new start date, I need that difference to be the final Days_Empty count.

 

Property_NumberBedspace_NumberTenancy_NameStart_DateEnd_DateDays_Empty
PROP-000017BEDS-000100T-00331602/02/2025 0
PROP-000017BEDS-000101T-00331704/07/201911/10/20190
PROP-000017BEDS-000101T-00333611/10/201918/10/20190
PROP-000017BEDS-000101T-00333718/10/201931/10/20190
PROP-000017BEDS-000101T-00333831/10/201922/11/20194
PROP-000017BEDS-000101T-00340427/11/201907/03/20200
PROP-000017BEDS-000102T-00331822/07/201906/10/20200
PROP-000024BEDS-000126T-00303404/03/201916/09/20190
PROP-000024BEDS-000126T-00316416/09/201909/10/20190
PROP-000024BEDS-000126T-00317009/10/201905/12/201913
PROP-000024BEDS-000126T-00352723/12/201905/02/20200
PROP-000024BEDS-000211T-00303503/02/201625/09/20190
PROP-000024BEDS-000211T-00305425/09/201926/09/20192
PROP-000024BEDS-000211T-00305529/09/201907/07/20210


Thanks in advance!

1 ACCEPTED SOLUTION
v-dineshya
Community Support
Community Support

Hi @RichOB ,

Thanks for reaching out to the Microsoft fabric community forum. 

 

Create a Calculated Column
You can use the following DAX expression for your Days_Empty calculated column:

Days_Empty =
VAR CurrentBedspace = 'Tenancies'[Bedspace_Number]
VAR CurrentEndDate = 'Tenancies'[End_Date]
VAR CurrentStartDate = 'Tenancies'[Start_Date]


VAR NextStartDate =
CALCULATE(
MIN('Tenancies'[Start_Date]),
FILTER(
'Tenancies',
'Tenancies'[Bedspace_Number] = CurrentBedspace &&
'Tenancies'[Start_Date] > CurrentStartDate
)
)

RETURN

IF(
ISBLANK(CurrentEndDate),
0,

IF(
ISBLANK(NextStartDate),
DATEDIFF(CurrentEndDate, TODAY(), DAY),
MAX(0, DATEDIFF(CurrentEndDate, NextStartDate, DAY))
)
)

If you find this post helpful, please mark it as an "Accept as Solution" and consider giving a KUDOS. Feel free to reach out if you need further assistance.
Thanks and Regards

View solution in original post

6 REPLIES 6
v-dineshya
Community Support
Community Support

Hi @RichOB ,

Thanks for reaching out to the Microsoft fabric community forum. 

 

Create a Calculated Column
You can use the following DAX expression for your Days_Empty calculated column:

Days_Empty =
VAR CurrentBedspace = 'Tenancies'[Bedspace_Number]
VAR CurrentEndDate = 'Tenancies'[End_Date]
VAR CurrentStartDate = 'Tenancies'[Start_Date]


VAR NextStartDate =
CALCULATE(
MIN('Tenancies'[Start_Date]),
FILTER(
'Tenancies',
'Tenancies'[Bedspace_Number] = CurrentBedspace &&
'Tenancies'[Start_Date] > CurrentStartDate
)
)

RETURN

IF(
ISBLANK(CurrentEndDate),
0,

IF(
ISBLANK(NextStartDate),
DATEDIFF(CurrentEndDate, TODAY(), DAY),
MAX(0, DATEDIFF(CurrentEndDate, NextStartDate, DAY))
)
)

If you find this post helpful, please mark it as an "Accept as Solution" and consider giving a KUDOS. Feel free to reach out if you need further assistance.
Thanks and Regards

Hi @RichOB ,

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and consider giving a KUDOS. Feel free to reach out if you need further assistance.

 

Regards,

Dinesh

Hi @RichOB ,

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and consider giving a KUDOS. Feel free to reach out if you need further assistance.

 

Regards,

Dinesh

jdbuchanan71
Super User
Super User

Did you add this as a calculated column on your table?  It is not meant to be a measure.

jdbuchanan71
Super User
Super User

@RichOB 

Give this a try.  You would add it as a calculated column.

The large results like 1838 are bacause there is no next start date so it is using today's date per your 3rd rule.

Days Empty = 
VAR _Start = 'Table'[Start_Date]
VAR _End = 'Table'[End_Date]
VAR _NextStart =
    COALESCE (
        CALCULATE (
            MIN ( 'Table'[Start_Date] ),
            ALLEXCEPT ( 'Table', 'Table'[Bedspace_Number], 'Table'[Property_Number] ),
            'Table'[Start_Date] > _Start
        ),
        TODAY ()
    )
VAR _Days = INT ( _NextStart - _End )
RETURN 
    IF ( ISBLANK ( 'Table'[End_Date] ), 0, _Days )

jdbuchanan71_0-1742389416490.png

 

Hi @jdbuchanan71 thanks so much for your help. I think this is almost exactly what I need but something is up with it. Sometimes bullet point 3 works, like in example BEDS-000061 where the days empty are correct at 0, and sometimes (e.g. Beds-000106) it's counting from the previous end date to today's date, even though the newer start date should override that and change it to 0.  Any idea why that would be? thanks

 

Bed106.pngBed61.png

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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