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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
powertechbi
Frequent Visitor

Count Number Range Date

Good afternoon

I have a spreadsheet that shows me the period of entry and exit of a patient and the total number of days.
I need to calculate the total number of days that are within the date filter period.
In the example I highlighted I have a range from 09/27 to 10/07. I only need to calculate the days of the month that are in the filter (September).

 

DUVIDA2.jpg

2 ACCEPTED SOLUTIONS
OktayPamuk80
Helper V
Helper V

Hi,

You could do following:

- You have a calendar table using calendar = CALENDARAUTO()

- In your existing table, I assume you have something like Patientnumber/ID 

- Using below formula to create a table in the table view using DAX, you can have the a new table with patient and each day between the dates in/out:

 

Solution =
SELECTCOLUMNS(

      GENERATE('Table', DATESBETWEEN('calendar'[Date],'Table'[in], 'Table'[out])),
     "Patient",'Table'[Patient],
     "Month",'Table'[mes],
     "PatientDate", 'calendar'[Date]

)

 

Can you try this out?

Regards,

Oktay

 

Did I answer your question? Then please mark my post as the solution.

If I helped you, click on the Thumbs Up to give Kudos.

View solution in original post

danextian
Super User
Super User

Hi @powertechbi ,

 

Using a separate dates table, you can write a measure that calculates the row count  within a specific date ranges.

Days Count = 
CALCULATE (
    COUNTROWS ( Dates ),
    KEEPFILTERS (
        Dates[Date] >= SELECTEDVALUE ( StartEnd[Start] )
            && Dates[Date] <= SELECTEDVALUE ( StartEnd[End] )
    )
)

 

danextian_0-1728217726179.png

 

 Please see attached sample pbix.





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

3 REPLIES 3
danextian
Super User
Super User

Hi @powertechbi ,

 

Using a separate dates table, you can write a measure that calculates the row count  within a specific date ranges.

Days Count = 
CALCULATE (
    COUNTROWS ( Dates ),
    KEEPFILTERS (
        Dates[Date] >= SELECTEDVALUE ( StartEnd[Start] )
            && Dates[Date] <= SELECTEDVALUE ( StartEnd[End] )
    )
)

 

danextian_0-1728217726179.png

 

 Please see attached sample pbix.





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.
OktayPamuk80
Helper V
Helper V

Hi,

You could do following:

- You have a calendar table using calendar = CALENDARAUTO()

- In your existing table, I assume you have something like Patientnumber/ID 

- Using below formula to create a table in the table view using DAX, you can have the a new table with patient and each day between the dates in/out:

 

Solution =
SELECTCOLUMNS(

      GENERATE('Table', DATESBETWEEN('calendar'[Date],'Table'[in], 'Table'[out])),
     "Patient",'Table'[Patient],
     "Month",'Table'[mes],
     "PatientDate", 'calendar'[Date]

)

 

Can you try this out?

Regards,

Oktay

 

Did I answer your question? Then please mark my post as the solution.

If I helped you, click on the Thumbs Up to give Kudos.

Hi,

Your question is not clear.  Share data in a format that can be pasted in an MS Excel file.  Show the expected result very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.