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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
bdeleur
Helper III
Helper III

Discharge department

Hi,

 

I want to make a report witch contains the following information.

Out of a big data file I want to extract the follow up department.

So I have department A and how many have a transfer (discharge) to deparment B & C etc.

 

ReferenceStart dateEnd dateDischarge (out of hospital)Department
11-11-2022 16:0010-11-2022 10:11 A
110-11-2022 10:11  B
22-11-2022 15:353-11-2022 13:343-11-2022 13:34A
31-11-2022 09:152-11-2022 10:24 A
32-11-2022 10:243-11-2022 18:123-11-2022 18:12C

 

So you can see that reference 1 transfer from department A to B at 10-11-2022 10:11. 

Reference 2 is discharged out of the hospital direct from department A.

Reference 3 transfers to department C and gets discharged out of that department (I don't want to know that discharge, only the report of department A to witch department the patient is transferd or discharged).

 

The file contains every department in the hospital.

 

Hope some can make the measure because with my knowledge... 🙂

1 ACCEPTED SOLUTION

@bdeleur 
For now this is what I can provide you. The difference between Count 2 and Count 3 is that count 3 shall not count discharged from same department unless there is a discharge date. The difference shall not be noticed using the sample data as there are no blanks in the end date.

1.png

View solution in original post

24 REPLIES 24
tamerj1
Super User
Super User

Hi @bdeleur 
Please refer to attached sample file with the proposed solution

2.png1.png

Count = 
SUMX ( 
    VALUES ( 'Table'[Reference] ),
    VAR CurrentTable = CALCULATETABLE ( 'Table' ) 
    VAR FirstRecord = TOPN ( 1, CurrentTable, 'Table'[Start date], ASC )
    VAR LastRecord = TOPN ( 1, CurrentTable, 'Table'[Start date] )
    VAR FirstDepartment = MAXX ( FirstRecord, 'Table'[Department] )
    VAR LastDepartment = MAXX ( LastRecord, 'Table'[Department] )
    RETURN
        IF ( 
            FirstDepartment <> LastDepartment
                && MAX ( 'To'[Department] ) = LastDepartment
                && MAX ( 'FROM'[Department] ) = FirstDepartment,
            1
        )

Hi,

 

I applied the code and it seems to work fine. I have to do and check to the outcome to be sure. Just 1 thing is missing: the code doesn't count the patients who have a discharge out of hospital.

How can we do that?

@bdeleur 
Please try

Count =
SUMX (
    VALUES ( 'Table'[Reference] ),
    VAR CurrentTable =
        CALCULATETABLE ( 'Table' )
    VAR FirstRecord =
        TOPN ( 1, CurrentTable, 'Table'[Start date], ASC )
    VAR LastRecord =
        TOPN ( 1, CurrentTable, 'Table'[Start date] )
    VAR FirstDepartment =
        MAXX ( FirstRecord, 'Table'[Department] )
    VAR LastDepartment =
        MAXX ( LastRecord, 'Table'[Department] )
    VAR DischargeDate =
        MAXX ( LastRecord, 'Table'[End Date] )
    RETURN
        IF (
            AND ( FirstDepartment = LastDepartment, DischargeDate <> BLANK () )
                && MAX ( 'To'[Department] ) = LastDepartment
                && MAX ( 'FROM'[Department] ) = FirstDepartment,
            1
        )
)

Now the matrix stays empty when I apply the code in your file.

@bdeleur 
I guess you are right. Sorry did not test. Pleas try

Count =
SUMX (
    VALUES ( 'Table'[Reference] ),
    VAR CurrentTable =
        CALCULATETABLE ( 'Table' )
    VAR FirstRecord =
        TOPN ( 1, CurrentTable, 'Table'[Start date], ASC )
    VAR LastRecord =
        TOPN ( 1, CurrentTable, 'Table'[Start date] )
    VAR FirstDepartment =
        MAXX ( FirstRecord, 'Table'[Department] )
    VAR LastDepartment =
        MAXX ( LastRecord, 'Table'[Department] )
    VAR DischargeDate =
        MAXX ( LastRecord, 'Table'[End Date] )
    RETURN
        IF (
            OR (
                FirstDepartment = LastDepartment
                    && DischargeDate <> BLANK (),
                MAX ( 'To'[Department] ) = LastDepartment
                    && MAX ( 'FROM'[Department] ) = FirstDepartment
            ),
            1
        )
)

I get some information now. But I'm trying to understand what I see.

I see the movements for every department but I don't see the next department.

I think I didn't meanson that well enough, sorry for that. And I like to see it like this:

bdeleur_1-1677674085344.png

 

This is when I selected/slice or filter department A

@bdeleur 
For now this is what I can provide you. The difference between Count 2 and Count 3 is that count 3 shall not count discharged from same department unless there is a discharge date. The difference shall not be noticed using the sample data as there are no blanks in the end date.

1.png

Hi @tamerj1 ,

 

Sorry for the delay. It was a bussy week. 

The count seams to work.

I have a question still: the totals give a differnt count the the sum in the matrix.

bdeleur_0-1678782496785.png

And I want to skip the count the movement between the same department, it isn't relevant.

Can you help me to understand it?

HI @bdeleur 
I can understand when the total counts less. That is expected. If the same reference extends over the two months then it will be counted in both months while at the total level it will be counted once. Therefore, this is a non-additive calculation by nature like distinctcount. However, it is up to your business logic to determine whether to force additivty or not.
Don't be confused about the scenarios where the total counts more. Notice that this only happens when Feb returns blank value. Which means that some references were neither counted in Feb. nor in Mar. Apparently one record in Feb. and one record on Mar. so it will be counted in neither but the in the total level.

To exclude same department movements just return to the very first solution.

Tnx for the answer. When I use my calander the count is correct, so I will use that.

Tnx for all your help, coudn't done it whitout you and I learned a lot. 

I will accept your help as the solution.

@bdeleur 
Initially the matrix analysis was based on "From" "To". Now I see a different matrix with "Months" in the columns of the matrix. For me this is a completely different analysis. Please clarify precisely what are you trying to accomplish.

Sorry for the confusion. With my short of knowledge I thought it was possible if you identifie the movements (matrix "from" to "to") you can count how many movements (unique reference) from a department to another, where you can filter the start department. So how many references are moved from A to B, to C etc and when you change the filter from B to A, to C etc. Displayed per date (month will do).

I gave you the data, is it helpfull?

@bdeleur 
If based on the start date and you have a dimDate table then I guess it should work. 

@bdeleur 
Sorry I didn't notice your reply. In order to provide your with accurate solution I need a sample dummy data (large just enough to provide significant output) along with the expected results. You can do that in excel or whatever tool you prefer. A sample PBIX file would also be great.

Hi, yes I understand that. I'll export my data and anomymize it.

@tamerj1I know you're very busy but please don't forget me 🙂

Hi @tamerj1 ,

 

Tnx. I will aply it to my data and see what the code makes of it. I will come back with the result.

andhiii079845
Super User
Super User

Yes, you can have one filter for the starting and one filter for the ending department. 

But i need more example data to create the measure and you have to make more clear how you handle or want to see the discharge out of the hospital. Also what is with cases like A -> B -> A -> out of the hospital how you count it? without the station between start and end? 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi, @andhiii079845 

 

A movement between departments uses the start and end date. When the end date and dismissal date are the same then the patient is discharged form that department.

 

patient 1 only had a transfer a to B, no discharge out of hospital

patient 2 didn't moved to another department and gets discharged out of hospital

patient 3 moved from department  A to B and gets discharged out of B

 

Is that what you need?

Thank you for the explanation. So the discharge out of the hospital is not relevant, right? How you want to handle the case if a person go from A to B to C or A to B to A. ? Should every transfer should be count ? 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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