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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rwamorim
Frequent Visitor

hospital occupancy rate

Guys, good night. I don't know if you can help me, the problem is very difficult, anyway ... I have a table with the date of hospitalization and the patient discharge date. I also have the bed he was admitted to. In another table I have the total number of beds in the hospital. With this information, I would like to get the month bed hospitalization rate. The calculation to get this rate is: Hospital occupancy rate = (number of patients per month / number of available beds per month) x 100 With the information I have I should be able to get this rate, but I have a problem. The patient may be in hospital for months, so the function should distribute the time he was hospitalized for the respective month. I broke my head and couldn't. If anyone can help, the patients would be very grateful because I am doing this to a public hospital. Thank you and look forward to a return.

1 ACCEPTED SOLUTION

Alright,

 

So the hard part is to find the number of patients pr night and sum it over a month. The number of beds should be simpler, at least if the number of beds are fairly static.

 

First I added an index to the Internacao-table in power query, in order to make the measure a bit slimmer.
Next I could not identify a date/calendar table, so I created one. It only contains date and months.

 

The measure then looks like this:

Number of patients pr day =
VAR m =
    SELECTEDVALUE ( Dates[month] )
RETURN
    COUNTROWS (
        CALCULATETABLE (
            GENERATE (
                SUMMARIZE (
                    INTERNACAO;
                    INTERNACAO[Index];
                    INTERNACAO[data_internacao];
                    INTERNACAO[alta_medica]
                );
                FILTER (
                    Dates;
                    dates[Date] >= CALCULATE ( VALUES ( INTERNACAO[data_internacao] ) )
                        && dates[Date] <= CALCULATE ( VALUES ( INTERNACAO[alta_medica] ) )
                )
            );
            FILTER ( Dates; dates[month] = m )
        )
    )

In order for this code to work, Dates[Month] needs to be on the axis.

How this code works, it starts with the Generate-function. The first argument of this function is the Summarize of index, hospitalization date and discharge date. It would have been possible to skip the summarize and just used the full Iternacao-table, but then much more data would need to be stored in memory. The second argument of Generate is evaluated for each row of the first argument, and the dates are filtered by hospitalization date and discharge date for each customer. The index works as an unique identifier for each hospitalization. The resulting table is a table where each index has rows for all dates between hospitalization and discharge. To get it pr month, there is a calculatetable around the generate-statement, which only works if there is only one distinct month value in the current context. After that it is just a matter of counting the rows.  Check out index=574 to see that it works(hospitalizes in may, discharged in july). There are some gritty details which are not handled, for instance index=1 where hospitalization is at 01.05.2019 00:31 and discharged at 01.05.2019 09:05.

https://www.dropbox.com/s/kbsw5080bsppfz9/hospital%20occupancy%20rate%20Original.pbix?dl=0

cheers,
S

View solution in original post

6 REPLIES 6
sturlaws
Resident Rockstar
Resident Rockstar

Hi,
 you would make it a lot easier for anyone to help you if you add some sample data, and possibly a pbix-file as well:
How to Get Your Question Answered Quickly

With some relevant sample data, we would not have to guess on e.g. granularity. If you add pbix-sample, we don't have to guess on how you have modelled your data.

 

cheers,

Sturla

The variables I should use in the spreadsheet are:

"data_internacao" = date of hospitalization
"alta_medica" = date of patient departure
"leito" = beds the hospital has

(a) "alta_medica" - "data_internacao" = number of beds occupied
(b) distinct count "leito" * number of days in month = number of beds available

The problem is that the formula has to separate the days from occupied beds by month. If the patient was hospitalized 40 days, then 30 was one month and 10 another, for example.

Alright,

 

So the hard part is to find the number of patients pr night and sum it over a month. The number of beds should be simpler, at least if the number of beds are fairly static.

 

First I added an index to the Internacao-table in power query, in order to make the measure a bit slimmer.
Next I could not identify a date/calendar table, so I created one. It only contains date and months.

 

The measure then looks like this:

Number of patients pr day =
VAR m =
    SELECTEDVALUE ( Dates[month] )
RETURN
    COUNTROWS (
        CALCULATETABLE (
            GENERATE (
                SUMMARIZE (
                    INTERNACAO;
                    INTERNACAO[Index];
                    INTERNACAO[data_internacao];
                    INTERNACAO[alta_medica]
                );
                FILTER (
                    Dates;
                    dates[Date] >= CALCULATE ( VALUES ( INTERNACAO[data_internacao] ) )
                        && dates[Date] <= CALCULATE ( VALUES ( INTERNACAO[alta_medica] ) )
                )
            );
            FILTER ( Dates; dates[month] = m )
        )
    )

In order for this code to work, Dates[Month] needs to be on the axis.

How this code works, it starts with the Generate-function. The first argument of this function is the Summarize of index, hospitalization date and discharge date. It would have been possible to skip the summarize and just used the full Iternacao-table, but then much more data would need to be stored in memory. The second argument of Generate is evaluated for each row of the first argument, and the dates are filtered by hospitalization date and discharge date for each customer. The index works as an unique identifier for each hospitalization. The resulting table is a table where each index has rows for all dates between hospitalization and discharge. To get it pr month, there is a calculatetable around the generate-statement, which only works if there is only one distinct month value in the current context. After that it is just a matter of counting the rows.  Check out index=574 to see that it works(hospitalizes in may, discharged in july). There are some gritty details which are not handled, for instance index=1 where hospitalization is at 01.05.2019 00:31 and discharged at 01.05.2019 09:05.

https://www.dropbox.com/s/kbsw5080bsppfz9/hospital%20occupancy%20rate%20Original.pbix?dl=0

cheers,
S

sturlwas, good afternoon !!!
when I saw that you answered my messages I was very happy !! So, first of all thank you very much !!! I analyzed what you did. Dude, you're a genius !!!! You are very cool. Dude ... you're a god !!!! I have no words...

Thank you very much!!!

Congratulations...!!!

Wow.


(number of patients per month / number of available beds per month) x 100

With the information I have, I should get this rate, but I have a problem:

The patient may be hospitalized for more than one month, so the formula has to take this start date and discharge date and tell the number of days for each month. Then I have to multiply the beds by total days of that month. Then multiply by 100. This is very difficult for my head ...

These are the files. I started the panel but I have this problem.

 

Arquivos

 

Obrigado...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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