Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

IF AND ELSE THEN statements - learning curve

MaryCann
8 - Asteroid

Hello Alteryx community!  New to SQL here...  Scenario:  some patients are on AntiPsychotic medications as well as non-AntiPsychotic medication.  If a client is on Anti-Psychotic Medication I want the result to be "Client on Antipsychotic Medication" even if only 1 of their 10 medications is an AntiPsychotic...  As well as if they are on no AntiPsychotics, I want it to be "Not on AntiPsychotic Medication"My first formula here works, but, the second one does not...  What do you recommend?

MaryCann_0-1650552792780.png

 

11 REPLIES 11
IraWatt
17 - Castor
17 - Castor

IraWatt_1-1650553505111.png

 

One option which is easier then writing huge if statements is just to have a mapping table then joining it to your data. If it matches then use the mapped name for instance 'AntiPsychotic', if they don't map use the other name. I've attached an example below.  

IraWatt
17 - Castor
17 - Castor

Your second if formula doesn't work because there is no ELSE statement 

DavidSkaife
13 - Pulsar

Hi @MaryCann 

 

You should be able to simplify it to:

 

IF [Clauses] THEN "Client on Antipsychotic Medication"

ELSE "Client not on Antipsychotic Medication"

ENDIF

MaryCann
8 - Asteroid

Hi @DavidSkaife , like this, right:

MaryCann_0-1650557383101.png

 

DavidSkaife
13 - Pulsar

Correct! Although having the [Client_ID] part in there may not work, as will that field contain the "Antipsychotic Medication" wording if it's an ID field?

MaryCann
8 - Asteroid

Client ID does not contain the word "Antipsychotic Medication", but, since the extract is based on client services, meaning 1 client ID could be repeated covering many rows (a new service date=a new row), and the one medication in the medication column that the client is receiving may only state, like "ARIPiprazole" , and the other medications may be Aspirin, or Ibuprofen, etc. in with different service dates.  I felt the need to build a correlation...

 

Does that make sense?  I know sometimes the paragraph in my head makes sense, but, I have no idea if anyone else understands it!

DavidSkaife
13 - Pulsar

Makes sense!

 

You can drop that part of the clause as the formula will tag each row with them being on the drug (or not). Try it and run and see if you get the expected results and let me know :)

MaryCann
8 - Asteroid

Quick newby question for confirmation:  would that make the denominator the number of rows, or the number of clients?

FloraF
Alteryx
Alteryx

@MaryCann 

 

Hi Mary, 

 

I was able to get to what you are looking to accomplish, by doing the following. I would recommend 2 things though; first, of writing an IF statement, have the list of Antipsychotic Medications in another input. Second, for better performance, I would assign 0 for those patients who are not on Antipsychotic drugs and 1 for those who are on it, once all members/clients are assigned, I would rename the 0 and 1s. This will ensure better performance, especially as your list of clients will increase. I attached the workflow for your convenience as well. 

 

**If this solves the issue, please click on the like below" thank you!

 

FloraF_0-1650575395120.png

 

 

Labels