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
anwilkins
Resolver II
Resolver II

Count patients with both diagnosis for Venn Diagram

I'm trying to create a Venn Diagram to show a count of active patients who have been diagnosed with issues related to

1-Mental Health

2-Substance Use

3-Both

I used the following code to create a new column categorizing each patient 

**Categories =
IF(LEFT('MERGE_ICD'[ICD9Code], 2) = "F1","Substance Use","" &
IF(LEFT('MERGE_ICD'[ICD9Code], 2) = "F2","Mental Health","" &
IF(LEFT('MERGE_ICD'[ICD9Code], 2) = "F3","Mental Health","" &
IF(LEFT('MERGE_ICD'[ICD9Code], 2) = "F4","Mental Health","" &
IF(LEFT('MERGE_ICD'[ICD9Code], 2) = "F5","Mental Health","" &
IF(LEFT('MERGE_ICD'[ICD9Code], 2) = "F6","Mental Health","" &
IF(LEFT('MERGE_ICD'[ICD9Code], 2) = "F7","Mental Health","" &
IF(LEFT('MERGE_ICD'[ICD9Code], 2) = "F8","Mental Health","" &
IF(LEFT('MERGE_ICD'[ICD9Code], 2) = "F9","Mental Health","N/A")))))))))  

 

anwilkins_0-1652457139445.png
I then created two more columns where I associated the number 1 if the patient was in that category and a 0 if no.
**Value-MH = IF('MERGE_ICD'[**Categories] IN {"Mental Health"} ,1,0)
**Value-SU = IF('MERGE_ICD'[**Categories] IN {"Substance Use"} ,1,0)
My problem is that my diagram is not showing the overlap of patients who have been diagnoses with both mental health and substance use codes
anwilkins_1-1652457494120.png

Adding the filter to remove the "0" in one removes the capability to look for the "1 in the second 

anwilkins_2-1652457684111.png

 

 I also have measures to calculate the data but still cant get the diagram to work..any help is greatly appreciated
 
*Total SU Patients = CALCULATE([*Total Patients], MERGE_ICD[**Categories] = "Substance Use")
*Total MH Patients = CALCULATE([*Total Patients], MERGE_ICD[**Categories] = "Mental Health")
*Total Patients = DISTINCTCOUNT((MERGE_ICD[patient internal id]))
Here is a sample visual of the data structure
Patient IDCategoryService DateMH CodeSU CodeBoth  
55433Substance Use1/1/2022010Total MH = 4 
55433Substance Use1/2/202201 Total SU = 3
55433Substance Use1/3/202201 Total Both =2
88546Mental Health1/4/2022111  
88546Mental Health1/5/202211  
88546Mental Health1/8/202211  
88546Mental Health1/9/202201  
88546Mental Health1/10/202201  
88546Mental Health1/11/202211  
88546Mental Health1/12/202211  
25497Mental Health1/13/2022101  
25497Mental Health1/14/202210  
25497Mental Health1/19/202210  
25497Mental Health1/20/202210  
25497Mental Health1/21/202210  
25497Substance Use1/22/202211  
56142Mental Health1/23/2022100  
56142Mental Health1/24/202210  
56142Mental Health1/25/202210  
56142Substance Use1/30/202210  
56142Substance Use1/31/202210  
66525Substance Use2/1/2022100  
66525Substance Use2/2/202210  
66525Substance Use2/3/202210  
2 ACCEPTED SOLUTIONS
v-jingzhang
Community Support
Community Support

Hi @anwilkins 

 

You can create a new table with the following code

Table 2 = 
UNION (
    ROW ( "Mental Health", 1, "Substance Use", 0, "Number of Patients", CALCULATE(DISTINCTCOUNT('Table'[Patient ID]), FILTER('Table','Table'[MH Code]=1 && 'Table'[SU Code]=0) )),
    ROW ( "Mental Health", 0, "Substance Use", 1, "Number of Patients", CALCULATE(DISTINCTCOUNT('Table'[Patient ID]), FILTER('Table','Table'[MH Code]=0 && 'Table'[SU Code]=1) )),
    ROW ( "Mental Health", 1, "Substance Use", 1, "Number of Patients", CALCULATE(DISTINCTCOUNT('Table'[Patient ID]), FILTER('Table','Table'[MH Code]=1 && 'Table'[SU Code]=1) ))
)

vjingzhang_0-1652694860174.png

 

Then use this new table to create the Venn Diagram. 

vjingzhang_1-1652695016839.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

v-jingzhang
Community Support
Community Support

Hi @anwilkins 

 

Sorry I realized that there was a mistake in my previous solution which would count some overlapped patients more than once in the new table. Please try the new solution in this reply. This new solution doesn't have that problem. 

 

First create a table to summarize patients and categories that they have been diagnosed. 

Summarize Table = SUMMARIZE('Table','Table'[Patient ID],"MH Code",MAX('Table'[MH Code]),"SU Code",MAX('Table'[SU Code]))

vjingzhang_2-1652756107865.png

 

Then use data from the above table to create the table for Venn Diagram. 

Table 2 = 
UNION (
    ROW ( "Mental Health", 1, "Substance Use", 0, "Number of Patients", COUNTROWS ( FILTER('Summarize Table','Summarize Table'[MH Code]=1 && 'Summarize Table'[SU Code]=0) )),
    ROW ( "Mental Health", 0, "Substance Use", 1, "Number of Patients", COUNTROWS ( FILTER('Summarize Table','Summarize Table'[MH Code]=0 && 'Summarize Table'[SU Code]=1) )),
    ROW ( "Mental Health", 1, "Substance Use", 1, "Number of Patients", COUNTROWS ( FILTER('Summarize Table','Summarize Table'[MH Code]=1 && 'Summarize Table'[SU Code]=1) ))
)

vjingzhang_3-1652756120734.png

vjingzhang_4-1652756229651.png

 

The new pbix has been attached. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @anwilkins 

 

Sorry I realized that there was a mistake in my previous solution which would count some overlapped patients more than once in the new table. Please try the new solution in this reply. This new solution doesn't have that problem. 

 

First create a table to summarize patients and categories that they have been diagnosed. 

Summarize Table = SUMMARIZE('Table','Table'[Patient ID],"MH Code",MAX('Table'[MH Code]),"SU Code",MAX('Table'[SU Code]))

vjingzhang_2-1652756107865.png

 

Then use data from the above table to create the table for Venn Diagram. 

Table 2 = 
UNION (
    ROW ( "Mental Health", 1, "Substance Use", 0, "Number of Patients", COUNTROWS ( FILTER('Summarize Table','Summarize Table'[MH Code]=1 && 'Summarize Table'[SU Code]=0) )),
    ROW ( "Mental Health", 0, "Substance Use", 1, "Number of Patients", COUNTROWS ( FILTER('Summarize Table','Summarize Table'[MH Code]=0 && 'Summarize Table'[SU Code]=1) )),
    ROW ( "Mental Health", 1, "Substance Use", 1, "Number of Patients", COUNTROWS ( FILTER('Summarize Table','Summarize Table'[MH Code]=1 && 'Summarize Table'[SU Code]=1) ))
)

vjingzhang_3-1652756120734.png

vjingzhang_4-1652756229651.png

 

The new pbix has been attached. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

v-jingzhang
Community Support
Community Support

Hi @anwilkins 

 

You can create a new table with the following code

Table 2 = 
UNION (
    ROW ( "Mental Health", 1, "Substance Use", 0, "Number of Patients", CALCULATE(DISTINCTCOUNT('Table'[Patient ID]), FILTER('Table','Table'[MH Code]=1 && 'Table'[SU Code]=0) )),
    ROW ( "Mental Health", 0, "Substance Use", 1, "Number of Patients", CALCULATE(DISTINCTCOUNT('Table'[Patient ID]), FILTER('Table','Table'[MH Code]=0 && 'Table'[SU Code]=1) )),
    ROW ( "Mental Health", 1, "Substance Use", 1, "Number of Patients", CALCULATE(DISTINCTCOUNT('Table'[Patient ID]), FILTER('Table','Table'[MH Code]=1 && 'Table'[SU Code]=1) ))
)

vjingzhang_0-1652694860174.png

 

Then use this new table to create the Venn Diagram. 

vjingzhang_1-1652695016839.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Thanks! I have it working but still don't understand why I needed to create a new table vs just adding calculated columns to the existing table where the data resides. Thanks!

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.