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

Become a Certified Power BI Data Analyst! Prepare for Exam PL-300 with expert-led live sessions. Get registered!

Reply
RichOB
Post Patron
Post Patron

Need help with Day Count measure please

Hi, I need to count the amount of days a dog is in a kennel. Specifically, I need help with a measure that sets TODAY as the end date for when either there is no End_Date or when the Status is Current. The end goal is to get a total count of the historic and current combined into a table:

KennelDogStart_DateEnd_Date StatusDay_Count
1Max24/02/202404/03/2024Historic10
1Charles04/03/202425/07/2024Historic144
1Lila25/07/2024 Current369
2Milo01/06/202426/08/2024Historic87
3Rex08/09/202410/10/2024Historic33
4Birdie01/11/202430/12/2024Historic61
4Bob30/12/2024 Current144
     848


Thanks

Rich

5 REPLIES 5
v-hashadapu
Community Support
Community Support

Hi @RichOB ,
I hope the information shared was helpful. If you have any additional questions or would like to explore the topic further, feel free to reach out. If any of the responses resolved your issue, please mark it "Accept as solution" and give it a 'Kudos' to support other members in the community.
Thank you!

v-hashadapu
Community Support
Community Support

Hi @RichOB ,
I wanted to follow up and see if youโ€™ve had a chance to review the information provided here.
If any of the responses helped solve your issue, please consider marking it "Accept as Solution" and giving it a 'Kudos' to help others easily find it.
Let me know if you have any further questions!

 

v-hashadapu
Community Support
Community Support

Hi @RichOB , Thank you for reaching out to the Microsoft Community Forum.

 

Please try below (I assumed kennel as table name):

Day_Count =

SUMX(

    'Kennel',

    VAR StartDate = 'Kennel'[Start_Date]

    VAR EndDateRaw =

        IF(

            ISBLANK('Kennel'[End_Date]) || 'Kennel'[Status] = "Current",

            TODAY(),

            'Kennel'[End_Date]

        )

    VAR EndDate = MIN(EndDateRaw, TODAY())  -- Prevent future dates

    VAR DayCount =

        IF(

            NOT ISBLANK(StartDate) && NOT ISBLANK(EndDate) && StartDate <= EndDate,

            DATEDIFF(StartDate, EndDate, DAY) + 1,

            0

        )

    RETURN

        DayCount

)

 

If this helped solve the issue, please consider marking it โ€œAccept as Solutionโ€ and giving a โ€˜Kudosโ€™ so others with similar queries may find it more easily. If not, please share the details, always happy to help.
Thank you.

DataNinja777
Super User
Super User

Hi @RichOB ,

 

You can create a DAX measure that calculates the number of days a dog is in a kennel by using DATEDIFF to find the difference between the start date and either the end date or todayโ€™s date if the end date is blank and the status is "Current". Use SUMX to iterate over the table and sum the day counts across all rows.

Day_Count = 
SUMX (
    'KennelTable',
    DATEDIFF(
        'KennelTable'[Start_Date],
        IF (
            NOT ISBLANK('KennelTable'[End_Date]),
            'KennelTable'[End_Date],
            IF (
                'KennelTable'[Status] = "Current",
                TODAY(),
                'KennelTable'[End_Date]
            )
        ),
        DAY
    )
)

This measure assumes that both Start_Date and End_Date are properly formatted as date fields. If you're seeing incorrect values, check that there are no time components or text format issues in the date fields.

 

Best regards,

johnt75
Super User
Super User

Try

Day Count =
SUMX (
    'Table',
    VAR EndDate =
        IF (
            ISBLANK ( 'Table'[End Date] )
                || 'Table'[Status] = "Current",
            TODAY (),
            'Table'[End Date]
        )
    VAR Result = EndDate - 'Table'[Start Date]
    RETURN
        Result
)

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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