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
Anonymous
Not applicable

Filter then group a table

Hi,

 

I have a rather unique requirement. I am currently working with medical information and I need to determine how long a patient is admitted to hospital for a respirtory infection. The data is in the following format, where each row is a patient event / episode:

 

Patient Episode Example.PNG

 

I first need to filter the table and return only those rows where the column 'ConslidatedDiagnosisValues' contains either J18 or J20 or J45. I then need to group the table by UniquePracticeID and UniquePatientID and calculate how long the patient was admitted to hospital. To do this i need to search for '0173' within the 'ConsolidatedChargeCodes'. This would mark the date when the patient was admitted to hospital. For each day the patient remained in hospital a 0111 code is charged. In the example above the patient had 2 stays in hospital. The first started on the 7th July 2017 and ended 13th July 2017. The second started on the 27th August 2017 and ended on the 31st August 2017.

 

I would like to create a new table with this information grouped as follows:

 

Group Patient Admitted Ex.PNG

 

Thanks for your help

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

For your requirement, you could create the two calculated column and the measure below.

 

DateOfServiceMin =
CALCULATE (
    MIN ( 'Table1'[DateOfSubmission] ),
    ALLEXCEPT ( Table1, Table1[ConsolidatedDiagnosisValues] )
)

DateOfServiceMax =
CALCULATE (
    MAX ( 'Table1'[DateOfSubmission] ),
    ALLEXCEPT ( 'Table1', Table1[ConsolidatedDiagnosisValues] )
)

AdmittedDays =
DATEDIFF (
    MAX ( 'Table1'[DateOfServiceMin] ),
    MAX ( 'Table1'[DateOfServiceMax] ),
    DAY
)
    + 1

Here is the output.

 

output.PNG

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Stachu
Community Champion
Community Champion

are you looking for DAX or M solution?

also, can you paste sample of your data in text format (e.g. copy from Excel)?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Hi @Stachu,

 

Looking for a DAX solution

 

Data as text:

 

DateOfSubmissionUniquePracticeIDUniquePatientIDConsolidatedDiagnosisValuesConsolidatedChargeCodes
2017/07/07 0:0014331181011J20.90145|0147|0173|0201
2017/07/08 0:0014331181011J20.90111|0201
2017/07/09 0:0014331181011J20.90111|0201
2017/07/11 0:0014331181011J20.90111|0201
2017/07/12 0:0014331181011J20.90111|0201
2017/07/13 0:0014331181011J20.90111|0201
2017/08/27 0:0014331181011J18.00147|0173|0201
2017/08/28 0:0014331181011J18.90111|0201
2017/08/29 0:0014331181011J18.90111|0201
2017/08/30 0:0014331181011J18.90111|0201
2017/08/31 0:0014331181011J18.90111|0201

 

UniquePracticeIDUniquePatientIDDateOfServiceMinDateOfServiceMaxAdmittedDays
143311810112017/07/072017/07/137
143311810112017/08/272017/08/315

 

Thanks.

Hi @Anonymous,

 

For your requirement, you could create the two calculated column and the measure below.

 

DateOfServiceMin =
CALCULATE (
    MIN ( 'Table1'[DateOfSubmission] ),
    ALLEXCEPT ( Table1, Table1[ConsolidatedDiagnosisValues] )
)

DateOfServiceMax =
CALCULATE (
    MAX ( 'Table1'[DateOfSubmission] ),
    ALLEXCEPT ( 'Table1', Table1[ConsolidatedDiagnosisValues] )
)

AdmittedDays =
DATEDIFF (
    MAX ( 'Table1'[DateOfServiceMin] ),
    MAX ( 'Table1'[DateOfServiceMax] ),
    DAY
)
    + 1

Here is the output.

 

output.PNG

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.