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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
danguy2099
Frequent Visitor

Count number of patients each day

Count number of patients each day
a minute ago

Hi

 

I need to help to make a count of patients that are in beds each day in hospitals. My data looks like this:

Hospital Patient_ID Admission_date Discharge_date

HospitalA 1 10.05.2021 13.05.2021
HospitalB 2 11.05.2021 16.05.2021
HospitalA 3 08.05.2021 15.05.2021

 

 

My expected output is like this:

date count_of_patients
07.05.2021 0
08.05.2021 1
09.05.2021 1
10.05.2021 2
11.05.2021 3
12.05.2021 3
13.05.2021 3
14.05.2021 2
15.05.2021 2
16.05.2021 1

 

and my final diagram is like this with possibility to have a slicer for hospital :

 

danguy2099_0-1648413928151.png

 

 

How can I make a measure in DAX that gives me what I want?

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Picture1.png

 

Patient Count: =
CALCULATE (
    COUNTROWS ( Data ),
    FILTER (
        Data,
        Data[Admission_date] <= MAX ( 'Calendar'[Date] )
            && Data[Discharge_date] >= MIN ( 'Calendar'[Date] )
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Picture1.png

 

Patient Count: =
CALCULATE (
    COUNTROWS ( Data ),
    FILTER (
        Data,
        Data[Admission_date] <= MAX ( 'Calendar'[Date] )
            && Data[Discharge_date] >= MIN ( 'Calendar'[Date] )
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

This solution worked out beautifully.  Simple, but truly effective solution. Thanks a lot !!!

amitchandak
Super User
Super User

@danguy2099 , one of these two blogs on mine should help you

 

https://community.powerbi.com/t5/Community-Blog/How-to-divide-distribute-values-between-start-date-o...

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.