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
AgeOfEgos
Helper I
Helper I

Conditional Column based on the presence of two other columns having a value (grouped by patient ID)

I want a list of patients that take 2 (Or more) medication types at the same time.  The table would be;

 

Name                     Benzos____________Opioids___________Medication

Patient A                 Y                               N                         Xanax

Patient B                 Y                               N                         Xanax

Patient C                 Y                               N                         Xanax

Patient C                 N                              Y                         Lortab

Patient D                N                               Y                          Lortab

Patient E                Y                                N                         Xanax

Patient E                N                               Y                          Hydrocodone

 

 

Ideally, my visual would only display Patient C and Patient E (Those patients that had both a Benzo and Opioid medication, although different rows).  I can't group by--as that will break the rest of my report.  If I try a new Conditional Column (Or custom column with an IF statement), since it evaluates row by row without grouping by Patient--I end up with the same issue.  Thanks for any help!

1 ACCEPTED SOLUTION
PattemManohar
Community Champion
Community Champion

@AgeOfEgos Please try this using "New Column" option

 

MultiMedicationFlag = 
IF(AND(PatMedication[Benzos]="Y",PatMedication[Opioids]="Y"),"Y",
IF(AND(PatMedication[Benzos]="Y",COUNTROWS(FILTER(ALL(PatMedication),PatMedication[Opioids]="Y" && PatMedication[Name] = EARLIER(PatMedication[Name])))>0),"Y",
IF(AND(PatMedication[Opioids]="Y",COUNTROWS(FILTER(ALL(PatMedication),PatMedication[Benzos]="Y" && PatMedication[Name] = EARLIER(PatMedication[Name])))>0),"Y","N")
)
)

image.png





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

Proud to be a PBI Community Champion




View solution in original post

2 REPLIES 2
PattemManohar
Community Champion
Community Champion

@AgeOfEgos Please try this using "New Column" option

 

MultiMedicationFlag = 
IF(AND(PatMedication[Benzos]="Y",PatMedication[Opioids]="Y"),"Y",
IF(AND(PatMedication[Benzos]="Y",COUNTROWS(FILTER(ALL(PatMedication),PatMedication[Opioids]="Y" && PatMedication[Name] = EARLIER(PatMedication[Name])))>0),"Y",
IF(AND(PatMedication[Opioids]="Y",COUNTROWS(FILTER(ALL(PatMedication),PatMedication[Benzos]="Y" && PatMedication[Name] = EARLIER(PatMedication[Name])))>0),"Y","N")
)
)

image.png





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

Proud to be a PBI Community Champion




That was brilliant, thank you!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 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.

August Carousel

Fabric Community Update - August 2024

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