Reputation: 3
Trying to find a formula that would allow me to show certain values.
Example:
I want to see Aspirin and Warfarin and (one or more of the next 3 values) Clopidogrel or Prasugrel or Ticagrelor.
Patient1 takes:
Aspirin Warfarin Clopidgrel
Patient 2 takes: Aspirin Warfarin
Right now I am seeing both patient 1 and patient 2 and I only want to see patients like patient 1 that shows the 3 different medications.
Please help and thank you in advance. I am using crystal reports 2008.
Upvotes: 0
Views: 1598
Reputation:
I suggest adding something like the following lines to the SQL select clause:
count(distinct case when medication in ('Aspirin', 'Warfarin')
then medication end)
over (partition by patient) as mandatory_meds,
count(distinct case when medication in ('Clopidogrel', 'Prasugrel', 'Ticagrelor')
then medication end)
over (partition by patient) optional_meds,
- then adding the following conditions to the SQL where clause:
and mandatory_meds = 2 and optional_meds >= 1
Alternatively, you could achieve a similar result in Crystal by:
if {myTable.medication} = "Aspirin" or {myTable.medication} = "Warfarin"
then {myTable.medication}
if {myTable.medication} = "Clopidogrel" or {myTable.medication} = "Prasugrel"
or {myTable.medication} = "Ticagrelor" then {myTable.medication}
DistinctCount({@mandatory_meds})=2 and DistinctCount({@optional_meds})>=1
Upvotes: 1