Salesforce Marketing Cloud AMPscript Guide: IIF() & IF-ELSE with Real-Time Business Use Cases
Use Case 1: Personalized Greeting Using IIF()
What is the Business Requirement?
A company wants to personalize email greetings based on the subscriber's gender.
Male subscribers should see Mr.
Female subscribers should see Ms.
Instead of writing a full IF-ELSE block, we can use the IIF() function to return a value directly.
Algorithm
START
Read Gender
IF Gender = Male
Display Mr.
ELSE
Display Ms.
END
END
IIF Syntax
IIF(condition, value_if_true, value_if_false)
AMPscript Code
%%[
VAR @Gender,@Greeting
SET @Gender = AttributeValue("Gender")
SET @Greeting = IIF(@Gender == "Male","Mr.","Ms.")
]%%
%%=v(@Greeting)=%%
Expected Output
Record 1
Gender = Male
Output
Mr.
Record 2
Gender = Female
Output
Ms.
Use Case 2: Loyalty Member Classification Using IIF()
What is the Business Requirement?
A company has a loyalty program and wants to display different benefits based on the customer's membership status.
Gold Members → Premium Benefits
Other Members → Standard Benefits
Since only two outcomes are possible, the IIF() function is a perfect choice.
Algorithm
START
Read MemberStatus
IF MemberStatus = Gold
Display Premium Benefits
ELSE
Display Standard Benefits
END
END
IIF Syntax
IIF(condition, value_if_true, value_if_false)
AMPscript Code
%%[
VAR @MemberStatus,@Benefits
SET @MemberStatus = AttributeValue("MemberStatus")
SET @Benefits = IIF(
@MemberStatus == "Gold",
"Premium Benefits",
"Standard Benefits"
)
]%%
%%=v(@Benefits)=%%
Expected Output
Record 1
MemberStatus = Gold
Output
Premium Benefits
Record 2
MemberStatus = Silver
Output
Standard Benefits
Record 3
MemberStatus = Bronze
Output
Standard Benefits
Use Case 3: Dynamic Discount Assignment Using IIF()
What is the Business Requirement?
An e-commerce company wants to reward high-spending customers with better discounts.
Customers who spend more than ₹10,000 receive a 20% discount.
All other customers receive a 10% discount.
Using IIF(), we can quickly assign the appropriate discount without writing a full IF-ELSE block.
Algorithm
START
Read TotalPurchase
IF TotalPurchase > 10000
Assign 20% OFF
ELSE
Assign 10% OFF
END
END
IIF Syntax
IIF(condition, value_if_true, value_if_false)
AMPscript Code
%%[
VAR @TotalPurchase,@Discount
SET @TotalPurchase = AttributeValue("TotalPurchase")
SET @Discount = IIF(
@TotalPurchase > 10000,
"20% OFF",
"10% OFF"
)
]%%
Your Discount: %%=v(@Discount)=%%
Expected Output
Record 1
TotalPurchase = 15000
Output
Your Discount: 20% OFF
Record 2
TotalPurchase = 10000
Output
Your Discount: 10% OFF
Record 3
TotalPurchase = 5000
Output
Your Discount: 10% OFF
Use Case 4: Age Verification Using IIF()
What is the Business Requirement?
A company wants to determine whether a customer is an Adult or a Minor based on their age.
Age 18 or above → Adult
Below 18 → Minor
This is commonly used in industries where age restrictions apply, such as banking, insurance, gaming, alcohol, and financial services.
Algorithm
START
Read Age
IF Age >= 18
Display Adult
ELSE
Display Minor
END
END
IIF Syntax
IIF(condition, value_if_true, value_if_false)
AMPscript Code
%%[
VAR @Age,@Status
SET @Age = AttributeValue("Age")
SET @Status = IIF(
@Age >= 18,
"Adult",
"Minor"
)
]%%
Customer Type: %%=v(@Status)=%%
Expected Output
Record 1
Age = 25
Output
Customer Type: Adult
Record 2
Age = 18
Output
Customer Type: Adult
Record 3
Age = 16
Output
Customer Type: Minor
Use Case 5: Cart Abandonment Journey Using IIF()
What is the Business Requirement?
An e-commerce company wants to send different messages based on whether a customer abandoned their shopping cart.
Cart Abandoned = True → Encourage customer to complete the purchase.
Cart Abandoned = False → Thank the customer for shopping.
This helps recover lost sales and improve conversion rates.
Algorithm
START
Read IsCartAbandoned
IF IsCartAbandoned = True
Display "Complete Your Purchase Today"
ELSE
Display "Thank You For Shopping"
END
END
IIF Syntax
IIF(condition, value_if_true, value_if_false)
AMPscript Code
%%[
VAR @IsCartAbandoned,@Message
SET @IsCartAbandoned = AttributeValue("OrderStatus")
SET @Message = IIF(
@IsCartAbandoned == "Pending",
"Complete Your Purchase Today",
"Thank You For Shopping"
)
]%%
%%=v(@Message)=%%Expected Output
Record 1
IsCartAbandoned = Pending
Output
Complete Your Purchase Today
Record 2
IsCartAbandoned = Confirmed/Shipped/Processing
Output
Thank You For Shopping
Use Case 6: Mobile App Adoption Using IIF()
What is the Business Requirement?
A company wants to promote its mobile application to customers.
If the customer is already an app user, show "Open App".
If the customer is not an app user, show "Download App".
This helps improve customer experience by directing users to the appropriate action.
Algorithm
START
Read IsAppUser
IF IsAppUser = Yes
Display "Open App"
ELSE
Display "Download App"
END
END
IIF Syntax
IIF(condition, value_if_true, value_if_false)
AMPscript Code
%%[
VAR @IsAppUser,@CTA
SET @IsAppUser = AttributeValue("IsAppUser")
SET @CTA = IIF(
@IsAppUser == "Yes",
"Open App",
"Download App"
)
]%%
Call To Action: %%=v(@CTA)=%%
Expected Output
Record 1
IsAppUser = Yes
Output
Call To Action: Open App
Record 2
IsAppUser = No
Output
Call To Action: Download App
Use Case 7: Lead Scoring Using IIF()
What is the Business Requirement?
A company wants to classify leads based on their engagement score.
Leads with a score greater than 80 are considered Hot Leads.
Leads with a score of 80 or below are considered Cold Leads.
This helps sales and marketing teams prioritize high-potential prospects.
Algorithm
START
Read Score
IF Score > 80
Classify as Hot Lead
ELSE
Classify as Cold Lead
END
END
IIF Syntax
IIF(condition, value_if_true, value_if_false)
AMPscript Code
Using your DE field Score
%%[
VAR @Score,@LeadStatus
SET @Score = AttributeValue("Score")
SET @LeadStatus = IIF(
@Score > 80,
"Hot Lead",
"Cold Lead"
)
]%%
Lead Status: %%=v(@LeadStatus)=%%
Expected Output
Record 1
Score = 95
Output
Lead Status: Hot Lead
Record 2
Score = 88
Output
Lead Status: Hot Lead
Record 3
Score = 72
Output
Lead Status: Cold Lead
Record 4
Score = 40
Output
Lead Status: Cold Lead
Use Case 8: Dynamic Subject Line Using IIF()
What is the Business Requirement?
A company wants to personalize email subject lines based on subscriber engagement.
Subscribers who have opened emails more than 5 times are considered engaged.
Less engaged subscribers receive a different subject line to encourage interaction.
This helps improve open rates and customer engagement.
Algorithm
START
Read OpenCount
IF OpenCount > 5
Display "We Miss You Less!"
ELSE
Display "We Miss You!"
END
END
IIF Syntax
IIF(condition, value_if_true, value_if_false)
AMPscript Code
%%[
VAR @OpenCount,@SubjectLine
SET @OpenCount = AttributeValue("OpenCount")
SET @SubjectLine = IIF(
@OpenCount > 5,
"We Miss You Less!",
"We Miss You!"
)
]%%
Subject Line: %%=v(@SubjectLine)=%%
Expected Output
Record 1
OpenCount = 10
Output
Subject Line: We Miss You Less!

Record 2
OpenCount = 7
Output
Subject Line: We Miss You Less!

Record 3
OpenCount = 2
Output
Subject Line: We Miss You!
Use Case 9: Membership Discount Using Nested IIF()
What is the Business Requirement?
A company wants to provide different discounts based on the customer's loyalty tier.
Gold Members → 30% OFF
Silver Members → 20% OFF
All Other Members → 10% OFF
Since there are more than two possible outcomes, a Nested IIF() can be used.
Algorithm
START
Read LoyaltyStatus
IF LoyaltyStatus = Gold
Assign 30% OFF
ELSE IF LoyaltyStatus = Silver
Assign 20% OFF
ELSE
Assign 10% OFF
END
END
AMPscript Code
%%[
VAR @LoyaltyStatus,@Discount
SET @LoyaltyStatus = AttributeValue("LoyaltyStatus")
SET @Discount = IIF(
@LoyaltyStatus == "Gold",
"30% OFF",
IIF(
@LoyaltyStatus == "Silver",
"20% OFF",
"10% OFF"
)
)
]%%
Your Discount: %%=v(@Discount)=%%
Expected Output
Record 1
LoyaltyStatus = Gold
Output
Your Discount: 30% OFF
Record 2
LoyaltyStatus = Silver
Output
Your Discount: 20% OFF
Record 3
LoyaltyStatus = Bronze
Output
Your Discount: 10% OFF
Use Case 1: VIP Customer Discount Using IF-ELSE
What is the Business Requirement?
An e-commerce company wants to reward high-value customers with different discount percentages based on their purchase amount.
Customers spending more than ₹10,000 receive a 20% discount.
All other customers receive a 10% discount.
Unlike IIF(), IF-ELSE is used because it is easier to extend later with additional business rules.
Algorithm
START
Read TotalPurchase
IF TotalPurchase > 10000
Assign 20% Discount
ELSE
Assign 10% Discount
ENDIF
Display Discount
END
AMPscript Code
%%[
VAR @TotalPurchase,@Discount,@Coupon
SET @TotalPurchase = AttributeValue("TotalPurchase")
IF @TotalPurchase > 10000 THEN
SET @Discount = "20% OFF"
SET @Coupon = "VIP20"
ELSE
SET @Discount = "10% OFF"
SET @Coupon = "SAVE10"
ENDIF
]%%
Discount: %%=v(@Discount)=%%<br>
Coupon Code: %%=v(@Coupon)=%%
Expected Output
Record 1
TotalPurchase = 15000
Output
Discount: 20% OFF
Coupon Code: VIP20
Record 2
TotalPurchase = 5000
Output
Discount: 10% OFF
Coupon Code: SAVE10
Use Case 2: Cart Abandonment Campaign Using IF-ELSE
What is the Business Requirement?
An e-commerce company wants to send different messages depending on whether a customer abandoned their cart.
If the cart is abandoned, encourage the customer to complete the purchase.
Otherwise, thank the customer for shopping.
This is one of the most common Journey Builder and email personalization use cases in Salesforce Marketing Cloud.
Algorithm
START
Read IsCartAbandoned
IF IsCartAbandoned = True
Show Recovery Message
ELSE
Show Thank You Message
ENDIF
Display Message
END
AMPscript Code
Using your DE field IsCartAbandoned
%%[
VAR @IsCartAbandoned,@Message,@Coupon
SET @IsCartAbandoned = AttributeValue("IsCartAbandoned")
IF @IsCartAbandoned == "True" THEN
SET @Message = "Complete Your Purchase Today"
SET @Coupon = "SAVE15"
ELSE
SET @Message = "Thank You For Shopping"
SET @Coupon = ""
ENDIF
]%%
%%=v(@Message)=%%
%%[ IF NOT EMPTY(@Coupon) THEN ]%%
<br>Coupon Code: %%=v(@Coupon)=%%
%%[ ENDIF ]%%
Expected Output
Record 1
IsCartAbandoned = True
Output
Complete Your Purchase Today
Coupon Code: SAVE15
Record 2
IsCartAbandoned = False
Output
Thank You For Shopping
Use Case 3: Mobile App Promotion Using IF-ELSE
What is the Business Requirement?
A company wants to promote its mobile application differently based on whether the customer already uses the app.
Existing App Users → Show "Open App"
Non-App Users → Show "Download App"
This helps improve app engagement while encouraging new users to install the application.
Algorithm
START
Read IsAppUser
IF IsAppUser = Yes
Show Open App CTA
ELSE
Show Download App CTA
ENDIF
Display CTA
END
AMPscript Code
%%[
VAR @IsAppUser,@CTA,@AppLink
SET @IsAppUser = AttributeValue("IsAppUser")
IF @IsAppUser == "Yes" THEN
SET @CTA = "Open App"
SET @AppLink = "myapp://home"
ELSE
SET @CTA = "Download App"
SET @AppLink = "https://play.google.com/store"
ENDIF
]%%
CTA: %%=v(@CTA)=%%<br>
Link: %%=v(@AppLink)=%%
Expected Output
Record 1
IsAppUser = Yes
Output
CTA: Open App
Link: myapp://home
Record 2
IsAppUser = No
Output
CTA: Download App
Link: https://play.google.com/store
Use Case 4: Loyalty Program Using IF-ELSE
What is the Business Requirement?
A company wants to provide different benefits to customers based on their loyalty status.
Gold Members → Premium Benefits
Other Members → Standard Benefits
This helps reward loyal customers and improve customer retention.
Algorithm
START
Read LoyaltyStatus
IF LoyaltyStatus = Gold
Assign Premium Benefits
ELSE
Assign Standard Benefits
ENDIF
Display Benefits
END
AMPscript Code
%%[
VAR @LoyaltyStatus,@Benefits,@Offer
SET @LoyaltyStatus = AttributeValue("LoyaltyStatus")
IF @LoyaltyStatus == "Gold" THEN
SET @Benefits = "Premium Benefits"
SET @Offer = "30% OFF"
ELSE
SET @Benefits = "Standard Benefits"
SET @Offer = "10% OFF"
ENDIF
]%%
Benefits: %%=v(@Benefits)=%%<br>
Offer: %%=v(@Offer)=%%
Expected Output
Record 1
LoyaltyStatus = Gold
Output
Benefits: Premium Benefits
Offer: 30% OFF
Record 2
LoyaltyStatus = Silver
Output
Benefits: Standard Benefits
Offer: 10% OFF

Record 3
LoyaltyStatus = Bronze
Output
Benefits: Standard Benefits
Offer: 10% OFF

Use Case 5: Healthcare Appointment Reminder Using IF-ELSE
What is the Business Requirement?
A healthcare provider wants to send appointment reminders only to patients who have a scheduled appointment.
If an appointment exists → Send reminder message.
If no appointment exists → Show a general healthcare message.
This ensures patients receive relevant communication and reduces missed appointments.
Algorithm
START
Read Status
IF Status = Active
Send Appointment Reminder
ELSE
Send General Healthcare Message
ENDIF
Display Message
END
AMPscript Code
%%[
VAR @Status,@Message,@CTA
SET @Status = AttributeValue("Status")
IF @Status == "Active" THEN
SET @Message = "You have an upcoming appointment. Please arrive 15 minutes early."
SET @CTA = "View Appointment"
ELSE
SET @Message = "Stay healthy! Schedule your next health checkup today."
SET @CTA = "Book Appointment"
ENDIF
]%%
Message: %%=v(@Message)=%%<br>
CTA: %%=v(@CTA)=%%
Expected Output
Record 1
Status = Active
Output
Message: You have an upcoming appointment. Please arrive 15 minutes early.
CTA: View Appointment
Record 2
Status = Inactive
Output
Message: Stay healthy! Schedule your next health checkup today.
CTA: Book Appointment
Use Case 6: Lead Qualification Using IF-ELSE
What is the Business Requirement?
A company wants to classify leads based on their engagement score so that sales teams can focus on high-potential prospects.
Score greater than 80 → Hot Lead
Score less than or equal to 80 → Cold Lead
This helps prioritize sales efforts and improve conversion rates.
Algorithm
START
Read Score
IF Score > 80
Classify as Hot Lead
ELSE
Classify as Cold Lead
ENDIF
Display Lead Status
END
AMPscript Code
%%[
VAR @Score,@LeadStatus,@Priority
SET @Score = AttributeValue("Score")
IF @Score > 80 THEN
SET @LeadStatus = "Hot Lead"
SET @Priority = "High"
ELSE
SET @LeadStatus = "Cold Lead"
SET @Priority = "Low"
ENDIF
]%%
Lead Status: %%=v(@LeadStatus)=%%<br>
Priority: %%=v(@Priority)=%%
Expected Output
Record 1
Score = 95
Output
Lead Status: Hot Lead
Priority: High
Record 2
Score = 88
Output
Lead Status: Hot Lead
Priority: High
Record 3
Score = 65
Output
Lead Status: Cold Lead
Priority: Low
Use Case 7: Banking Offer Personalization Using IF-ELSE
What is the Business Requirement?
A bank wants to personalize credit card offers based on a customer's credit score.
Customers with a high score receive a Platinum Card offer.
Other customers receive a Gold Card offer.
This helps banks target customers with the most appropriate financial products.
Algorithm
START
Read Score
IF Score > 80
Offer Platinum Card
ELSE
Offer Gold Card
ENDIF
Display Offer
END
AMPscript Code
%%[
VAR @Score,@CardType,@Benefits
SET @Score = AttributeValue("Score")
IF @Score > 80 THEN
SET @CardType = "Platinum Credit Card"
SET @Benefits = "Airport Lounge Access"
ELSE
SET @CardType = "Gold Credit Card"
SET @Benefits = "Cashback Rewards"
ENDIF
]%%
Recommended Card: %%=v(@CardType)=%%<br>
Benefit: %%=v(@Benefits)=%%
Expected Output
Record 1
Score = 95
Output
Recommended Card: Platinum Credit Card
Benefit: Airport Lounge Access
Record 2
Score = 72
Output
Recommended Card: Gold Credit Card
Benefit: Cashback Rewards
Use Case 8: Email Engagement Segmentation Using IF-ELSE
What is the Business Requirement?
A company wants to identify engaged and inactive subscribers based on their email engagement history.
Subscribers who opened an email within the last 30 days are considered Engaged.
Subscribers who have not opened an email in the last 30 days are considered Inactive.
This helps marketers send targeted campaigns and improve customer engagement.
Algorithm
START
Read LastOpenDays
IF LastOpenDays <= 30
Mark as Engaged Subscriber
ELSE
Mark as Inactive Subscriber
ENDIF
Display Segment
END
AMPscript Code
%%[
VAR @LastOpenDays,@Segment,@Campaign
SET @LastOpenDays = AttributeValue("LastOpenDays")
IF @LastOpenDays <= 30 THEN
SET @Segment = "Engaged Subscriber"
SET @Campaign = "New Product Launch"
ELSE
SET @Segment = "Inactive Subscriber"
SET @Campaign = "Win-Back Campaign"
ENDIF
]%%
Segment: %%=v(@Segment)=%%<br>
Campaign: %%=v(@Campaign)=%%
Expected Output
Record 1
LastOpenDays = 10
Output
Segment: Engaged Subscriber
Campaign: New Product Launch
Record 2
LastOpenDays = 25
Output
Segment: Engaged Subscriber
Campaign: New Product Launch
Record 3
LastOpenDays = 90
Output
Segment: Inactive Subscriber
Campaign: Win-Back Campaign
Enterprise Scenario: VIP Customer Segmentation Using IF-ELSE
What is the Business Requirement?
An enterprise retail company wants to identify VIP customers and provide exclusive rewards.
A customer qualifies as a VIP when:
LoyaltyStatus = Gold
TotalPurchase > ₹10,000
VIP customers should receive:
Premium Discount
Exclusive Coupon Code
VIP Journey Enrollment
All other customers receive standard offers.
Algorithm
START
Read LoyaltyStatus
Read TotalPurchase
IF LoyaltyStatus = Gold
AND TotalPurchase > 10000
Assign VIP Segment
Assign 30% Discount
Assign VIP Coupon
Assign VIP Journey
ELSE
Assign Standard Segment
Assign 10% Discount
Assign Standard Coupon
ENDIF
Display Offer
END
AMPscript Code
%%[
VAR @LoyaltyStatus,@TotalPurchase
VAR @Segment,@Discount,@Coupon,@Journey
SET @LoyaltyStatus = AttributeValue("LoyaltyStatus")
SET @TotalPurchase = AttributeValue("TotalPurchase")
IF @LoyaltyStatus == "Gold"
AND @TotalPurchase > 10000 THEN
SET @Segment = "VIP Customer"
SET @Discount = "30% OFF"
SET @Coupon = "VIP30"
SET @Journey = "VIP Journey"
ELSE
SET @Segment = "Standard Customer"
SET @Discount = "10% OFF"
SET @Coupon = "SAVE10"
SET @Journey = "Standard Journey"
ENDIF
]%%
Customer Segment: %%=v(@Segment)=%%<br>
Discount: %%=v(@Discount)=%%<br>
Coupon: %%=v(@Coupon)=%%<br>
Journey: %%=v(@Journey)=%%
Expected Output
Record 1
LoyaltyStatus = Gold
TotalPurchase = 15000
Output
Customer Segment: VIP Customer
Discount: 30% OFF
Coupon: VIP30
Journey: VIP Journey
Record 2
LoyaltyStatus = Silver
TotalPurchase = 15000
Output
Customer Segment: Standard Customer
Discount: 10% OFF
Coupon: SAVE10
Journey: Standard Journey
Record 3
LoyaltyStatus = Gold
TotalPurchase = 5000
Output
Customer Segment: Standard Customer
Discount: 10% OFF
Coupon: SAVE10
Journey: Standard Journey
Comments
Post a Comment