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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
RichOB
Post Patron
Post Patron

I need a help with a day count measure

Hi, I have 2 dog boarding kennels and want to know the day count between the previous Dog ending and new one starting for each room.

 

For example, the day difference between Dog1 and Dog2 in April 2024 A1 is 2 days.

 

I do not have the Days_to_Fill column in my source data.

 

LocationRoomDog_NumberStart_DateEnd_DateDays_to_Fill
ManchesterA1101/04/202410/04/20242
ManchesterA1213/04/202418/04/20247
ManchesterA1326/04/202428/04/20245
ManchesterA1403/05/202415/05/2024 
NewcastleB1501/07/202412/07/20244
NewcastleB1617/07/202423/07/202415
NewcastleB1708/08/202418/08/20242
NewcastleB1821/08/202425/08/2024 

 

Thanks

1 ACCEPTED SOLUTION

It is a calculated column

Difference = 
VAR NextStart =
    CALCULATE (
        MIN ( 'Table'[Start_Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Room] = EARLIER ( 'Table'[Room] )
                && 'Table'[Start_Date] > EARLIER ( 'Table'[Start_Date] )
        )
    )
RETURN
    DATEDIFF ( 'Table'[End_Date], NextStart, DAY )

danextian_0-1733913161338.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

7 REPLIES 7
Kedar_Pande
Super User
Super User

@RichOB 

DAX for a Calculated Column:

Days_to_Fill =
VAR CurrentStart = 'Table'[Start_Date]
VAR CurrentRoom = 'Table'[Room]
VAR CurrentLocation = 'Table'[Location]
VAR PreviousEnd =
MAXX(
FILTER(
'Table',
'Table'[Room] = CurrentRoom &&
'Table'[Location] = CurrentLocation &&
'Table'[End_Date] < CurrentStart
),
'Table'[End_Date]
)
RETURN
IF(
NOT ISBLANK(PreviousEnd),
DATEDIFF(PreviousEnd, CurrentStart, DAY),
BLANK()
)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

 

danextian
Super User
Super User

I'm pretty confused

danextian_0-1733912058837.png

Row 1: Apr 10 to 13 = 3 days

Row 2 : Apr 18 to Apr 26 = 8 days

 

These should be the differences in days

Location Room Dog_Number Start_Date End_Date Days_to_Fill difference
Manchester A1 1 01/04/2024 10/04/2024 2 3
Manchester A1 2 13/04/2024 18/04/2024 7 8
Manchester A1 3 26/04/2024 28/04/2024 5 5
Manchester A1 4 03/05/2024 15/05/2024    
Newcastle B1 5 01/07/2024 12/07/2024 4 5
Newcastle B1 6 17/07/2024 23/07/2024 15 16
Newcastle B1 7 08/08/2024 18/08/2024 2 3
Newcastle B1 8 21/08/2024 25/08/2024    

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian thanks for your reply. What Measure did you use to get that please?

 

Thanks

 

It is a calculated column

Difference = 
VAR NextStart =
    CALCULATE (
        MIN ( 'Table'[Start_Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Room] = EARLIER ( 'Table'[Room] )
                && 'Table'[Start_Date] > EARLIER ( 'Table'[Start_Date] )
        )
    )
RETURN
    DATEDIFF ( 'Table'[End_Date], NextStart, DAY )

danextian_0-1733913161338.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

This worked perfectly thank you!

AnkitaaMishra
Super User
Super User

Hi @RichOB , 
Please try below DAX : 

Days_to_Fill_Calculation =
VAR _CheckRoom = 'ExampleTable'[Room]
VAR _CheckLocation = 'ExampleTable'[Location]
VAR _CheckStartDate = 'ExampleTable'[Start_Date]
VAR _PrevEndDate =
    CALCULATE(
        MAX('ExampleTable'[End_Date]),
        FILTER(
            'ExampleTable',
            'ExampleTable'[Location] = _CheckLocation &&
            'ExampleTable'[Room] = _CheckRoom &&
            'ExampleTable'[End_Date] < _CheckStartDate
        )
    )
RETURN
IF(
    ISBLANK(_PrevEndDate),
    BLANK(),
    DATEDIFF(_PrevEndDate, _CheckStartDate, DAY) -1
)
Output : 
WhatsApp Image 2024-12-11 at 15.31.46.jpeg
You can adjust the formula (with or without -1)
Thanks,
Ankita

Hi @AnkitaaMishra thanks so much for your help. I'm having a DAX error of " Cannot convert value 'Manchester' of type Text to type True/False".  Do you know how I would solve this please?


Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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