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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
pui
Frequent Visitor

Array formula in DAX

I have some patients data in a hospital with admission date and discharge date.  I need to calculate how many patients are in the hospital on each day.  Sample data and expected output as below, I produced the expected output by excel array formula, no idea how to do it in Power BI.  

 

Logic

1. Count the admission date but not discharged date, e.g. the first patient is admitted on 1/1 and discharged on 3/1, he is counted as a patient on 1/1 and 2/1

2. Blank discharge date means patient is not yet discharged, so he is counted until the current date

 

Sample data

Admission date (dd/mm/yyyy)Discharged date (dd/mm/yyyy)
01/01/202303/01/2023
02/01/2023 
03/01/202305/01/2023
04/01/202312/01/2023
05/01/202310/01/2023

 

Expected output

DateNo. of patients
01/01/2023                            1
02/01/2023                            2
03/01/2023                            2
04/01/2023                            3
05/01/2023                            3
06/01/2023                            3
07/01/2023                            3
08/01/2023                            3
09/01/2023                            3
10/01/2023                            2
11/01/2023                            2
12/01/2023                            1
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1679379766678.png

 

 

Jihwan_Kim_0-1679379752276.png

 

No of patients measure: =
COUNTROWS (
    FILTER (
        Data,
        Data[Admission date (dd/mm/yyyy)] <= MAX ( 'Calendar'[Date] )
            && OR (
                Data[Discharged date (dd/mm/yyyy)] > MIN ( 'Calendar'[Date] ),
                Data[Discharged date (dd/mm/yyyy)] = BLANK ()
            )
    )
)

 

 

 


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

2 REPLIES 2
pui
Frequent Visitor

Hi @Jihwan_Kim 

 

Thank you so much for your quick reply!  It's very helpful, I've replicated to my dataset.  A follow-up question - Can I calculate the monthly average of the no. of patients measure?  (The sample data contains only Jan 2023 but the real data contains years of data)

 

Thank you!

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1679379766678.png

 

 

Jihwan_Kim_0-1679379752276.png

 

No of patients measure: =
COUNTROWS (
    FILTER (
        Data,
        Data[Admission date (dd/mm/yyyy)] <= MAX ( 'Calendar'[Date] )
            && OR (
                Data[Discharged date (dd/mm/yyyy)] > MIN ( 'Calendar'[Date] ),
                Data[Discharged date (dd/mm/yyyy)] = BLANK ()
            )
    )
)

 

 

 


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.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.