Combine Columns with Fallback Values
A contact list has a primary_email and a backup_email, and you want one
email column: the primary address when there is one, otherwise the backup.
Coalesce Columns checks the columns in the order you list them and copies
the first value that is not null into a new column.
You'll use: File Input → Coalesce Columns → File Output.
- 1InputFile Inputcontacts.csv
- 2TransformCoalesce Columnsprimary_email, backup_email →
email - 3OutputFile Outputcontacts_email
Sample data
Save this as contacts.csv. Customer 2 has no primary email, customer 3 has
neither, and customer 4 has a single space as the primary email.
customer_id,primary_email,backup_email
1,[email protected],[email protected]
2,,[email protected]
3,,
4," ",[email protected]Steps
- On Datasets, upload
contacts.csv. - In a new flow, add File Input. Set File type to CSV and Dataset
to
contacts.csv. - Add Coalesce Columns. In Columns (in priority order) pick
primary_emailfirst, thenbackup_email. Set New column toemail. - Leave Keep the original columns checked for now, so you can compare each source column with the result.
- Add File Output. Set File type to CSV (.csv) and Dataset name to
contacts_email. Connect the nodes in order and click Run.
Prefer to describe it?
With a provider key set up, upload the sample data, open a blank flow in the same project and ask the Flow assistant, for example: "create an email column from primary_email, falling back to backup_email." Review the proposed nodes and settings, then choose Apply and save. We ran this prompt on the sample data; see what the assistant built. Its flow can differ from the steps above in node order and names, so check each setting. The assistant never runs a flow, so click Run yourself.
Result
| customer_id | primary_email | backup_email | |
|---|---|---|---|
| 1 | [email protected] | [email protected] | [email protected] |
| 2 | null | [email protected] | [email protected] |
| 3 | null | null | null |
| 4 | " " | [email protected] | " " |
Check the result
Save the flow, click Preview, select the Coalesce Columns node and click
Run preview. Customer 2 should show [email protected] in email and
customer 3 should show null. Customer 4 shows an email that looks empty: that
is the space, and it is the row to fix.
Pitfalls
- Blank text is not null. A space, or an empty text produced by an earlier Strip spaces step, counts as a value and wins over the backup. If a blank should mean missing, fix it in the source file: an empty CSV cell is read as null.
- Order is priority. Put the most trusted column first. Coalesce never compares two values that are both set; customer 1 gets the primary address even though a backup exists.
- Both missing stays missing. Add Fill Nulls
after Coalesce if
emailneeds a placeholder. - Uncheck Keep the original columns only after checking the result. The
output then has
customer_idandemailonly. - To join text from several columns, such as first and last name, use Combine Columns instead.
Exported Python
Click Export in the editor toolbar. The pandas and polars tabs show
this code for the flow. It reads contacts.csv from the script's folder and
writes contacts_email.csv.
import pandas as pd
df_contacts = pd.read_csv('contacts.csv')
df_contacts = df_contacts.assign(email=lambda _d: _d['primary_email'].where(pd.notna, _d['backup_email']))
df_contacts.to_csv('contacts_email.csv', index=False)