Some weeks an attachment has data. Other weeks it's empty. You probably don't want to send an empty spreadsheet, but you also don't want to drop the whole email just because one file came back blank.

Conditional attachments solve this. You add a condition to each file on an email report, and PushMetrics checks the file before the email goes out. If the condition passes, the file is attached. If it doesn't, that one file is left out and the rest of the email still sends.

A condition can be as simple as "only if there's data", or a SQL query if you need something more specific.

Which attachments support conditions

Conditions work on data-based attachments, which are the files that have rows and columns behind them. You can add a condition to any CSV or Excel (XLSX) attachment produced by these tasks:

  • SQL Query
  • Tableau Export
  • Explore
  • File Download
  • Data Source

Tableau image (PNG) and PDF exports are also supported, with one extra step. Since an image or PDF has no data to query on its own, you turn on Also fetch data on the Tableau task first. See Conditions on images and PDFs below.

Attachments that aren't data files, such as Word (DOCX) or Google Slides (PPTX) exports, don't support conditions and are always sent.

Where to find it

Conditions live on the Email task. Open the email block and expand Advanced Options. You'll find a Conditional attachments section that lists every file the email attaches, each with its own toggle.

The Conditional attachments section in the Email task's Advanced Options, listing each attached file with its own toggle

Turn on the toggle for an attachment to add a condition. Any attachment you leave off is always sent, exactly like before.

Skip empty attachments

The default option is Skip if empty. The file is attached only when it has at least one row of data. If the export comes back empty that week, PushMetrics leaves it out and moves on. No SQL required.

This handles the most common case on its own: don't send this file if there's nothing in it.

Write a SQL condition

When you need more than a simple empty check, switch to Custom SQL. You write a query against the file, which is available as a table called file. The query should return a single true or false value. If it's true, the file is attached. If it's false, it's skipped.

SELECT COUNT(*) > 0 FROM file
SELECT COUNT(*) > 100 FROM file WHERE region = 'EU'

The Available columns chips above the editor show the file's real column names. Click one to drop it into your query so you don't have to remember exact spelling or capitalization.

Custom SQL mode showing the Skip if empty and Custom SQL buttons, clickable available-column chips, and a SQL condition editor querying the file table

If a column name has spaces or special characters, clicking its chip inserts it already quoted, for example "Distinct count of Customer Name".

Preview before you send

You don't have to run the whole report to test a condition. Once the attachment's source task has run, click Preview on the condition. PushMetrics runs it against the latest file and tells you the result right there:

  • Condition met, so this file would be attached.
  • Condition not met, so this file would be skipped.
A condition after clicking Preview, showing a green Condition met callout that says this file would be attached

Preview uses the latest run of the source task. If you haven't run it yet this session, run the task first with its Run button, then click Preview.

Use merge fields in a condition

If your report uses Dynamic Report Personalization (mail merge), your condition can reference the same merge fields you use in the subject and body. PushMetrics evaluates the condition once per recipient, so each person only gets the attachment when their slice of the data has rows.

SELECT COUNT(*) > 0 FROM file WHERE region = '{{ region }}'

Conditions on images and PDFs

A Tableau image (PNG) or PDF export is a picture, so it has no rows or columns to query on its own. To gate one on data, open the Tableau task's export options (the gear next to the attachment) and turn on Also fetch data (enables conditions).

The Tableau task's Export Options popover with the Also fetch data (enables conditions) toggle turned on

With this on, the task also pulls the view's underlying data when it runs. Now you can gate the image or PDF with Skip if empty or a SQL condition. The condition runs against the view's data, and the file you actually send is still the image.

This adds a small extra data fetch to that task's run, so only turn it on for the image or PDF attachments you want to gate. After you enable it, run the task once so the data is available.

Good to know

  • Only the failing attachment is skipped. The other files and the email body still send as normal.
  • A broken condition never drops your file. If a condition can't be evaluated, for example because of invalid SQL, PushMetrics keeps the attachment and logs the issue instead of quietly dropping data.
  • Every attachment has its own toggle and its own condition.
  • Conditions gate individual files. If instead you want to hold back the whole email whenever a CSV or Excel attachment comes back empty, use the email's separate Don't send if any attachment is empty option. As the name says, it suppresses the entire email when any data attachment has no rows, even if the others have data.

Frequently asked questions

What is the file table? It's the attachment's own contents, made available to your SQL as a table called file. For a CSV or Excel file that's the file's rows and columns. For a gated Tableau image or PDF, it's the view's underlying data.

Do I need to know SQL? No. Skip if empty needs no SQL at all. It just checks whether the file has any rows. Custom SQL is there for when you want a more specific rule.

Why is there no condition on my image or PDF attachment? Turn on Also fetch data (enables conditions) in the Tableau task's export options, then run the task again. Image and PDF attachments only get a condition once their data is available.

Does this affect scheduled runs? Yes. Conditions apply to every run of the report, whether it's scheduled, triggered by a webhook, or started with Run Now. Each run checks the files it just generated.

What happens to an attachment with no condition? It's always attached, just like before. Conditions are opt-in per file.

Which tasks can I add a condition to? Any task that produces a CSV or Excel attachment: SQL Query, Tableau Export, Explore, File Download and Data Source. Tableau image and PDF exports are supported too once you enable Also fetch data on the Tableau task. Word and Google Slides exports don't support conditions.