---
schema_version: "1"
id: 44b18c68407692122c61ca1a081320e3567834cd99155ec80898c37ca29f7cc1
title: AMPscript Functions for Einstein Email Recommendations
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/mktg/264-0-0/mc_pb_ampscript_functions_for_email_recommendations.md
canonical_url: https://help.salesforce.com/s/articleView?id=mktg.mc_pb_ampscript_functions_for_email_recommendations.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 1b54c4f45aa1aff0736634548c45c91efeb023f31224fc5000704e776b56881c
description: View a list of commonly used AMPscript functions for Einstein Email Recommendations.
products:
  - Marketing
  - Marketing Cloud Intelligence
release: "264"
---
# AMPscript Functions for Einstein Email Recommendations

View a list of commonly used AMPscript functions for Einstein Email Recommendations.

Use these functions to define email image templates, or for conditional formatting, data formatting, and sanitizing.

## Product Attributes

Replace the attribute name with the attribute value of the item to recommend.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%AttributeName%%`

## Conditional Operators

Conditional statements allow conditional display and formatting, such as a strikethrough over the regular price when items are on sale.

Operators where A and B can be a:

- string
- float
- product attribute or exact name from your catalog, such as `%%WidthInInches%%`

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small "><colgroup><col style="width:50%"> <col style="width:50%"></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">A &gt; B</td><td class="slds-cell-wrap" style="vertical-align:top;">True when A is greater than B</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">A &lt; B</td><td class="slds-cell-wrap" style="vertical-align:top;">True when A is less than B</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">A &gt;= B</td><td class="slds-cell-wrap" style="vertical-align:top;">True when A is greater than or equal to B</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">A &lt;= B</td><td class="slds-cell-wrap" style="vertical-align:top;">True when A is less than or equal to B</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">A == B</td><td class="slds-cell-wrap" style="vertical-align:top;">True when A equals B</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">A!= B</td><td class="slds-cell-wrap" style="vertical-align:top;">True when A isn’t equal to B</td></tr></tbody></table>

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

```
%%[ if a > b then ]%%
print this if statement is true
%%[ else ]%%
optional line that will print if statement if false
%%[ endif ]%%
```

## Logical Operators

Use logical operators to make compound conditions in if statements. Use only one logical operator in a condition.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small "><colgroup><col style="width:50%"> <col style="width:50%"></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">&amp;&amp;</td><td class="slds-cell-wrap" style="vertical-align:top;">Logical And - Executes when both conditions are true.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">||</td><td class="slds-cell-wrap" style="vertical-align:top;">Logical Or - Executes when either condition is true.</td></tr></tbody></table>

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%[ if a > b || b > c then ]%%`

Print if at least one condition is true

`%%[ endif ]%%`

`%%[ if a > b && b > c then ]%%`

Print if both conditions are true

`%%[ endif ]%%`

## Conversion Functions

**ToFloat**

Appending an item attribute key with ToFloat converts the value of a string field in your catalog to a floating-point number.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%WidthInInches%%` 12

`%%WidthInInchesToFloat%%` 12.0

**LengthNum**

Appending an item attribute key with LengthNum returns the length of the value in your catalog. Use LengthNum only within the statement.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%[if DisplayRegularPriceLengthNum < 5 then ]%% %%ProductName%% %%[else]%% %%DisplaySalePrice%% %%[ endif ]%%`

**LongestWordLength**

Append LongestWordLength to an item attribute key to convert the value to a string. This function calculates the longest word then returns a number for the length of that word.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%Description%%`

I love Einstein Email Recommendations

`%%DescriptionLongestWordLength%%`

15

## Display Functions

**Rating Stars**

Take the value stored in the Rating field and convert it to the number of stars where:

- **maximum\_value** is the highest ranking
- **color** is the color of the stars

The rating comes from the product's Rating attribute.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%= RatingStars(maximum_value, color) =%%`

**RegularPriceMain or SalePriceMain**

Outputs the integer part of the field mapped to RegularPrice or Price for streaming updates and SalePrice.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%RegularPriceMain%%` 34

`%%SalePriceMain%%` 29

**RegularPriceFractional or SalePriceFractional**

Outputs the fractional part of the field mapped to RegularPrice or Price for using streaming updates and SalePrice.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

The following example assumes that the recommended item is regularly priced at 34.50, but on sale for 29.99.

`%%RegularPriceFractional%%` 50

`%%SalePriceFractional%%` 99

**ToUpcase**

Outputs the value in the catalog in uppercase.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%AuthorToUpcase%%` MARK TWAIN

**FirstN**

Where N is a whole number, outputs the first N characters of value.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%AuthorFirst6%%` Mark T

**Split**

Usage: SplitDAtI

Where D is the delimiter and I is the index, splits the value returns the string at the given index. The delimiter can be longer than 1 character and the index can be negative.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_note.png)

Note Currently the Split function can’t be used inside an IF condition.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

When the value for _Colors_ is _Red~Blue~Green_: `%%ColorsSplit~At1%%` Blue

**Replace**

Usage: ReplaceAWithBEnd

Where A is the match substring and B is the replacement substring, it replaces the matches globally and outputs the value.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

`%%AuthorReplaceMarkWithSamuelEnd%%` Samuel Twain

**UpTo**

Usage: UpToNByDWithOEnd

Where N is a whole number, D is the delimiter, and O is an optional overflow text, outputs the value up to the N index of D with O appended when included. Values shorter than the limit return unaltered and values without a delimiter match within the limit returns blank.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

If the value for LongTitle is “Long~Item~Title” `%%LongTitleUpTo10By~With...End%%`: Long~Item…

`%%LongTitleUpTo9By~WithEnd%%`: Long

`%%LongTitleUpTo4By~WithEnd%%`: blank

`%%LongTitleUpTo9By~WithEnd%%`: Long

`%%LongTitleUpTo20By~WithEnd%%`: Long~Item~Title

**Chaining**

You can chain multiple functions together.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_data_management_and_analytics-264-0-0-production-enus/7988f60d-cd94-4b42-8836-dc11773564b5/images/icon_example.png)

Example

For example, if Author = Mark Twain `%%Author%%`: Mark Twain

`%%AuthorReplaceMarkWithSamuelEndReplaceTwainWithClemensEndToUpCase%%`: SAMUEL CLEMENS