How to Change Merge Field Values with Filters in Mail Merge
A filter changes a value from your sheet before Mail Merge puts the value in the email. Use a filter when a cell holds the right data in the wrong form, like a name in small letters or a date that should show the weekday. The filter doesn’t change your sheet.
To show a sentence only to some people, use a condition.
See a Filter Filled In
Section titled “See a Filter Filled In”Tom at Becker Bikes emails each customer when their order is ready. Customers typed their own names in the order form, so one name is in small letters and one is missing:
| First Name | Email Address | Bikes | Price | Pickup Date |
|---|---|---|---|---|
| angus | angus@example.com |
2 | 349 | Mar 13, 2027 |
daniel.okafor@example.net |
1 | 349 | Mar 16, 2027 |
Tom starts the greeting with a plain merge field, then adds one filter at a time:
| Tom writes | Angus reads | Daniel reads |
|---|---|---|
Hi {{First Name}}, |
Hi angus, |
Hi , |
Hi {? {{First Name}} | capitalize ?}, |
Hi Angus, |
Hi , |
Hi {? {{First Name}} | capitalize | default: "there" ?}, |
Hi Angus, |
Hi there, |
The plain merge field copies each cell as it is. The capitalize filter fixes Angus’s name, but Daniel’s cell is still empty. The default filter then fills in “there” for Daniel.
Tom uses two more filters in the same email, one for the total and one for the pickup date:
Hi {? {{First Name}} | capitalize | default: "there" ?},
Your order is ready. The total is €{? {{Price}} | times: {{Bikes}} ?}.Collect your order from {? {{Pickup Date}} | date: "%A, %B %-d" ?}.Angus reads a total of €698 and Saturday, March 13. Daniel reads a total of €349 and Tuesday, March 16.
Add a Filter to Your Template
Section titled “Add a Filter to Your Template”-
Go to Extensions > Mail Merge with Attachments > Open Mail Merge, open your campaign and move to the Template step.
-
Click where the value should appear. Type
{?, the merge field, a|, the filter and?}:{? {{First Name}} | capitalize ?} -
To use a second filter, type another
|and the filter. Mail Merge runs the filters from left to right, and each filter works on the result of the filter before it.{? {{First Name}} | capitalize | default: "there" ?} -
Click Send Test Email and send the email to yourself. The test uses row 2 of your sheet, so change the value in that row to check each result.
The merge field keeps its double curly braces inside {? and ?}. Type the quotes as straight quotes, and leave the filter as plain text with no bold or colour.
Give an Empty Cell a Fallback
Section titled “Give an Empty Cell a Fallback”The default filter prints other text when the cell is empty. Without the filter, Hi {{First Name}}, arrives as Hi , for Daniel.
Hi {? {{First Name}} | capitalize | default: "there" ?},Put default last. A filter after default changes the fallback text too, so default: "there" | capitalize prints There.
You can also add a fallback column to your sheet and leave the template as it is.
Fix Capital Letters
Section titled “Fix Capital Letters”| You write | Angus gets |
|---|---|
{? {{First Name}} | capitalize ?} |
Angus |
{? {{First Name}} | upcase ?} |
ANGUS |
{? {{First Name}} | downcase ?} |
angus |
The capitalize filter makes the first letter a capital and the other letters small. A cell with angus mcdonald becomes Angus mcdonald.
If your sheet has a full name in one column, three filters print the first name with a capital letter:
Hi {? {{Full Name}} | split: " " | first | capitalize ?},The split filter cuts the name at each space, and first keeps the first word.
Format a Date
Section titled “Format a Date”Mail Merge gets a date the way the cell shows it. To change every email, format the cell in Google Sheets. Use the date filter when you can’t change the sheet, or when one email shows the same date in two forms.
Tom starts with a plain merge field for the pickup date, then adds the date filter and one code at a time:
| Tom writes | Angus reads | Daniel reads |
|---|---|---|
{{Pickup Date}} |
Mar 13, 2027 |
Mar 16, 2027 |
{? {{Pickup Date}} | date: "%B" ?} |
March |
March |
{? {{Pickup Date}} | date: "%B %-d" ?} |
March 13 |
March 16 |
{? {{Pickup Date}} | date: "%A, %B %-d" ?} |
Saturday, March 13 |
Tuesday, March 16 |
The plain merge field copies the date as the cell shows it. The date filter prints only the parts you ask for, so %B gives the month name alone. %-d adds the day and %A adds the weekday. The filter copies the spaces and the comma between the codes as you type them.
The same codes in another order give other forms of the date:
| You write | Angus gets |
|---|---|
{? {{Pickup Date}} | date: "%B %-d, %Y" ?} |
March 13, 2027 |
{? {{Pickup Date}} | date: "%a, %-d %b" ?} |
Sat, 13 Mar |
{? {{Pickup Date}} | date: "%d/%m/%Y" ?} |
13/03/2027 |
{? {{Pickup Date}} | date: "%Y-%m-%d" ?} |
2027-03-13 |
Each code stands for one part of the date:
| Code | Meaning | Example |
|---|---|---|
%A |
Weekday name | Saturday |
%a |
Short weekday name | Sat |
%B |
Month name | March |
%b |
Short month name | Mar |
%-d |
Day, no leading zero | 13 |
%d |
Day, 2 digits | 13 |
%m |
Month number, 2 digits | 03 |
%Y |
Year, 4 digits | 2027 |
The date filter can read 2027-03-13, Mar 13, 2027 and 3/13/2027. The filter can’t read a date that starts with the day, such as 13/03/2027, and prints that date unchanged.
To add days to a date, turn the date into seconds, add the days, and format the result. One day is 86400 seconds, so 7 days is 604800:
We hold your order until {? {{Pickup Date}} | date: "%s" | plus: 604800 | date: "%B %-d" ?}.Do Arithmetic
Section titled “Do Arithmetic”Tom lets customers pay in three instalments, so each email shows the order total divided by 3. Every bike costs €349. Angus ordered 2 bikes and Daniel ordered 1:
| Customer | Price | Bikes |
|---|---|---|
| Angus | 349 |
2 |
| Daniel | 349 |
1 |
Tom starts with a plain merge field for the price, then adds one filter at a time:
| Tom writes | Angus reads | Daniel reads |
|---|---|---|
€{{Price}} |
€349 |
€349 |
€{? {{Price}} | times: {{Bikes}} ?} |
€698 |
€349 |
€{? {{Price}} | times: {{Bikes}} | divided_by: 3 ?} |
€232.66666666666666 |
€116.33333333333333 |
€{? {{Price}} | times: {{Bikes}} | divided_by: 3 | round: 2 ?} |
€232.67 |
€116.33 |
Each filter does one sum on the result of the filter before it. For Angus:
times: {{Bikes}}multiplies the price by the number of bikes. 349 × 2 gives the order total, 698.divided_by: 3splits the total into three instalments. 698 ÷ 3 gives 232.66666666666666, which has too many decimals.round: 2rounds the instalment to 2 decimals, which gives 232.67.
Type the currency sign in front of {?, as Tom does. Two more filters add and subtract:
| You write | Angus gets | What it does |
|---|---|---|
{? {{Bikes}} | plus: 1 ?} |
3 |
Adds |
{? {{Bikes}} | minus: 1 ?} |
1 |
Subtracts |
Check these before you send:
- The cell must hold a plain number. A number with a comma, a currency sign or a unit is text, so
$1,200gives a wrong result. Remove the signs first:{? {{Amount}} | remove: "$" | remove: "," | plus: 0 ?}gives1200. - Round the result. Arithmetic with decimals can give a long tail, such as
0.30000000000000004. End withround: 2. - No filter always prints two decimals.
148.5stays148.5, not148.50. For an amount like€698.00, add a column to your sheet that works out the total, and format that column as currency.
Where Filters Work
Section titled “Where Filters Work”Filters work in the Message, the Subject and the Sender name. For example, Tom’s subject can name the day:
Your bikes are ready for {? {{Pickup Date}} | date: "%A" ?}Mail Merge doesn’t read filters in Send to, CC, BCC or Reply-to.
Things to Know
Section titled “Things to Know”- A filter can’t go inside a condition.
{% if {{First Name}} | downcase == "angus" %}gives an error. Store the value first with{% assign name = {{First Name}} | downcase %}, then write{% if name == "angus" %}. See variables. - A filter prints text. If a filter writes HTML, such as
<br>, the email shows the HTML as typed. - Mail Merge never reads a value from your sheet as a filter. If a cell holds
{? … ?}, the email shows that text. - Filters work the same in every editor. They also work in the plain text part of the email.
The Scriptlets Reference lists every filter, with filters that shorten text, replace words and work on lists.
Troubleshooting
Section titled “Troubleshooting”The status column shows “Scriptlet error in the template”
Section titled “The status column shows “Scriptlet error in the template””A filter in your template has a mistake, so Mail Merge didn’t send the email for that row. The rest of the message says what to fix. For expected "|" before filter, the filter has curly quotes or formatted text. Type the filter again as plain text with straight quotes.
Fix the template, then run the campaign again. Mail Merge sends the rows with an error on the next run.
The date arrives unchanged
Section titled “The date arrives unchanged”The date filter can’t read the date in the cell. Change the cell’s format in Google Sheets so the date starts with the month or the year, like Mar 13, 2027 or 2027-03-13.
The number has a long row of decimals
Section titled “The number has a long row of decimals”Arithmetic with decimals isn’t always exact. Add | round: 2 as the last filter.
