AMPscript Course for Marketers - Functions (Format, Concat, Propercase...) - Chapter 3

Published by: Santiago Tabuenca on Sep 17, 2023 11:15:00 PM
 Santiago Tabuenca

AMPscript is a scripting language used in Salesforce Marketing Cloud to personalize and enhance marketing communications, such as emails and text messages. Functions in AMPscript are code blocks that perform specific tasks, such as data manipulation, mathematical calculations, and text formatting. Below, we will explore the general structure of an AMPscript function, different types of functions, and examples of some key functions.


 AMPscript Function



Structure of an AMPscript Function


The general structure of a function in AMPscript is as follows:


%%[ FunctionName(Argument1, Argument2, ...) ]%%



Types of Functions in AMPscriptTipos de Funciones en AMPscript:


1. Data Functions:

  • Lookup: Retrieves a value from a Data Extension.

  • LookupRows: Retrieves multiple rows from a Data Extension based on specified criteria.

  • RowCount: Returns the number of rows in a Data Extension.

  • Row: Returns a specific row from a Data Extension.

2. String Functions:


  • Concat: Concatenates text strings.

    • Example: SET @fullName = Concat(@firstName, " ", @lastName)
  • ProperCase: Converts the first letter of each word to uppercase.

    • Example: SET @properText = ProperCase(@text)
  • UpperCase: Converts text to uppercase.

    • Example: SET @upperText = UpperCase(@text)
  • LowerCase: Converts text to lowercase.

    • Example: SET @lowerText = LowerCase(@text)

3. Math Functions:


  • Add: Adds two numbers.

    • Example: SET @totalPrice = Add(@price, @discount)
  • Subtract: Subtracts two numbers.

    • Example: SET @subtotal = Subtract(@total, @discount)

  • Multiply: Multiplies two numbers.

    • Example: SET @totalToPay = Multiply(@unitPrice, @quantity)

  • Divide Divides two numbers.

    • Example: SET @average = Divide(@sum, @count)

  • Mod: Calculates the remainder of the division of two numbers.

    • Example: SET @remainder = Mod(@number, 2)

  • Random: Generates a random number within a range.

    • Example: SET @randomNumber = Random(1, 100)


Examples of Functions in AMPscript


Here are examples of some specific functions in AMPscript:


String Concatenation Example:

%%[ SET @firstName = "John" SET @lastName = "Doe" SET @fullName = Concat(@firstName, " ", @lastName) ]%%


Proper Case Conversion Example:

%%[ SET @text = "hello world" SET @properText = ProperCase(@text) ]%%


Mathematical Calculation Example:

%%[ SET @price = 100 SET @discount = 20 SET @finalPrice = Subtract(@price, @discount) ]%%


These are just basic examples, and there are many other functions in AMPscript that you can explore to customize your marketing communications. Each function has its own syntax and usage options, so it's advisable to consult the official Salesforce Marketing Cloud documentation for specific details on each function and how to use it effectively.

Remember that AMPscript is a powerful tool for message customization and data interaction, so it can make a significant difference in your marketing campaigns when used correctly.



In this video, you can watch this topic of functions explained in detail:



Download our ebook supporting the online course here:


ebooks amscript for marketers

If you liked this chapter of the Ampscript for Marketers course, you might be interested in reading:

If you liked this article, share it!

Topic: SF Marketing Cloud