IF Condition use cases

Mastering AMPscript Conditional Statements (IF / ELSEIF / ELSE)

Conditional statements allow you to make dynamic decisions within your Salesforce Marketing Cloud emails. By evaluating subscriber data, you can display tailored messages on the fly.

Basic Syntax

AMPscript Syntax
%%[
IF condition THEN
  /* Output text or code here */
ENDIF
]%%

Basic Example:

AMPscript Block
%%[
VAR @Age
SET @Age = 18

IF @Age == 18 THEN
]%%
Eligible
%%[
ENDIF
]%%

Project 1: Gold Customer Welcome Message

Requirements:

  • Create a sendable Data Extension called Customer_Status_DE
  • Import at least 10 customer records
  • Display a welcome message only for Gold customers
  • Use AttributeValue() and an IF condition
  • Do not use Lookup()
  • Test with Gold, Silver, and Bronze customers to verify outputs
Project 1 DE Preview
AMPscript Solution
%%[
VAR @Status
SET @Status = AttributeValue("Status")

IF @Status == "Gold" THEN 
]%%
Welcome Gold Member!
%%[
ELSE
]%%
Welcome Member
%%[
ENDIF
]%%

Project 2: Customer Age Validation

Requirements:

  • Create a sendable Data Extension called Customer_Age_DE (10+ records)
  • Check if a customer is 18 years or older using the comparison operator (>=)
  • If age is 18 or above, display eligibility message; otherwise, display nothing
  • Use AttributeValue() and avoid Lookup()
AMPscript Solution
%%[
VAR @Age, @SubscriberKey
SET @Age = AttributeValue("Age")
SET @SubscriberKey = AttributeValue("SubscriberKey")

IF @Age >= 18 THEN 
]%%
Hello %%=v(@SubscriberKey)=%%! You are eligible.
%%[
ENDIF
]%%

Project 3: India Customer Localization

Requirements:

  • Check if the subscriber's country attribute matches "India"
  • Display localized targeted copy depending on the country matched
Project 3 DE Preview
AMPscript Solution
%%[
VAR @Country, @SubscriberKey
SET @Country = AttributeValue("Country")
SET @SubscriberKey = AttributeValue("SubscriberKey")

IF @Country == "India" THEN 
]%%
Hello %%=v(@SubscriberKey)=%%, You are Indian.
%%[
ELSE
]%%
Hello %%=v(@SubscriberKey)=%%, You are not Indian.
%%[
ENDIF
]%%

Project 4: Mobile Number Validation Check

Requirements:

  • Verify if a mobile data field contains text or values using NOT EMPTY()
  • Fallback cleanly if no record exists
Project 4 DE Preview
AMPscript Solution
%%[
VAR @Mobile, @SubscriberKey
SET @Mobile = AttributeValue("Mobile")
SET @SubscriberKey = AttributeValue("SubscriberKey")

IF NOT EMPTY(@Mobile) THEN 
]%%
Hello %%=v(@SubscriberKey)=%%, your mobile number is %%=v(@Mobile)=%%.
%%[
ELSE
]%%
%%=v(@SubscriberKey)=%% Mobile Not exist.
%%[
ENDIF
]%%

Project 5: Birthday Celebration Block

Requirements:

  • Check a boolean flag structure evaluating if today is the user's birthday
Project 5 DE Preview
AMPscript Solution
%%[
VAR @IsBirthday, @SubscriberKey
SET @IsBirthday = AttributeValue("IsBirthday")
SET @SubscriberKey = AttributeValue("SubscriberKey")

IF @IsBirthday == "True" THEN 
]%%
Hello %%=v(@SubscriberKey)=%%, today is your birthday!
%%[
ENDIF
]%%

Project 6: High-Value Cart Rewards

Requirements:

  • Evaluate threshold numeric amounts and append bonus reward values for users spend above 5000
Project 6 DE Preview
AMPscript Solution
%%[
VAR @CartValue, @SubscriberKey
SET @CartValue = AttributeValue("CartValue")
SET @SubscriberKey = AttributeValue("SubscriberKey")

IF @CartValue > 5000 THEN 
]%%
Hello %%=v(@SubscriberKey)=%%, You got extra rewards!
%%[
ENDIF
]%%

Project 7: Email Verification Status

Requirements:

  • Identify whether the customer has a complete email structure present
Project 7 DE Preview
AMPscript Solution
%%[
VAR @Email, @SubscriberKey
SET @Email = AttributeValue("Email")
SET @SubscriberKey = AttributeValue("SubscriberKey")

IF NOT EMPTY(@Email) THEN 
]%%
Hello %%=v(@SubscriberKey)=%%, Your email is verified.
%%[
ELSE
]%%
Hello %%=v(@SubscriberKey)=%%, Your email is not verified.
%%[
ENDIF
]%%

Project 8: Premium Plan Validation

Requirements:

  • Isolate status classifications to deliver plan specific value strings
Project 8 DE Preview
AMPscript Solution
%%[
VAR @Plan, @SubscriberKey
SET @Plan = AttributeValue("Plan")
SET @SubscriberKey = AttributeValue("SubscriberKey")

IF @Plan == "Premium" THEN 
]%%
Hello %%=v(@SubscriberKey)=%%, You are premium member.
%%[
ELSE
]%%
Hello %%=v(@SubscriberKey)=%%, Your Plan is Basic.
%%[
ENDIF
]%%

Project 9: Salary Bonus Bracket

Requirements:

  • Identify high-income thresholds (>= 50000) to output dynamic statement rules
Project 9 DE Preview
AMPscript Solution
%%[
VAR @Salary, @SubscriberKey
SET @Salary = AttributeValue("Salary")
SET @SubscriberKey = AttributeValue("SubscriberKey")

IF @Salary >= 50000 THEN 
]%%
Hello %%=v(@SubscriberKey)=%%, You will get the bonus!
%%[
ELSE
]%%
Hello %%=v(@SubscriberKey)=%%, You are not eligible for bonus.
%%[
ENDIF
]%%

Project 10: Active Status Offers

Requirements:

  • Filter active users dynamically to display exclusive offers
Project 10 DE Preview
AMPscript Solution
%%[
VAR @Status, @SubscriberKey
SET @Status = AttributeValue("Status")
SET @SubscriberKey = AttributeValue("SubscriberKey")

IF @Status == "Active" THEN 
]%%
Hello %%=v(@SubscriberKey)=%%, you are eligible for offer.
%%[
ENDIF
]%%

Comments

Popular posts from this blog

IIF condition

AMPscript IF–THEN–ELSEIF–ELSE–ENDIF Notes and Use case