How to Duplicate Rows in Tableau
Ever found yourself staring at a dataset in Tableau, wishing you could just... make a copy of every row? It sounds strange at first, but duplicating rows is a surprisingly powerful technique for creating advanced visualizations like Sankey diagrams, advanced Gantt charts, path analysis, and slope graphs. This article will walk you through the most common and effective methods for duplicating your data right inside Tableau.
Why Duplicate Rows in Tableau Anyway?
Before we get into the "how," let's quickly cover the "why." Your data usually has one row per event or entity. For example, one row per customer, one row per sale, or one row per website session. This is great for most charts, but what if you want to visualize a path or a duration?
Imagine you have a list of marketing campaigns, each with a start date and an end date in a single row. If you want to plot this on a timeline, you need two points: one for the start and one for the end. Duplicating the row allows you to create these two distinct points from a single line of data.
Common use cases for duplicating data include:
- Data Densification: This is a fancy term for adding more data points to your set to enable specific chart types. It's the foundation for building complex charts that aren't natively supported.
- Sankey Diagrams: To build a Sankey, you need to "densify" your data to create the points needed to draw the smooth curves flowing from one category to another.
- Slope or Dumbbell Charts: To compare a "before" and "after" value, you need a point for the start and a point for the end. Duplicating the data for each item you're comparing is the first step.
- Path Analysis: To show a customer journey from step A to step B, you often need to duplicate records to create the start and end points of each path segment.
Essentially, whenever you need a single record in your original data to represent two or more points in your visualization, you'll need to duplicate it. Let's look at a few ways to do that.
Method 1: Using a Self-Union
The most straightforward method to duplicate every row in your data source is to union the data with itself. A union appends rows from one table to another. When you union a table with itself, you're effectively stacking an identical copy of the data right underneath the original, instantly doubling your row count.
This is my go-to recommendation for beginners because it doesn't require creating any external files or writing any code. You can do it all within the Tableau data source interface.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Step-by-Step Guide for Self-Unions
Let’s assume you’re working with a single Excel or CSV file called "Campaign_Data".
- Connect to your data: In Tableau, connect to your Excel file, CSV, or database table.
- Drag your table to the canvas: You will see your data table (let's say it's named 'Sheet1') appear in the data source canvas.
- Drag the same table again: Now, drag that same 'Sheet1' from the left-hand pane and drop it directly below the first table in the canvas. You'll see an orange drop area that says "Drag table to union."
That's it! Tableau will automatically create a union. You now have two copies of every single row in your data source.
Working with the Duplicated Data
When you create a union in Tableau, it adds two new columns to your data that help you identify which copy of the data a row belongs to:
[Table Name][Sheet Name]
The [Table Name] field is particularly useful. For the original set of data, its value will be 'Sheet1'. For the duplicated set, its value will be 'Sheet11' (Tableau appends a number to distinguish it). You can leverage this field in a calculated field to build your visualization.
For example, let's say you want to create a calculated field called "Point Type" to identify the start and end of a marketing campaign.
IF [Table Name] = 'Sheet1' THEN 'Start'
ELSEIF [Table Name] = 'Sheet11' THEN 'End'
ENDNow you can create another calculated field for the corresponding date:
IF [Point Type] = 'Start' THEN [Start Date]
ELSEIF [Point Type] = 'End' THEN [End Date]
ENDWith these calculations, you can now build a chart using the duplicated data, where each campaign has two distinct marks - one for its start and one for its end.
Method 2: Joining to a Model Table
Another powerful method involves creating a separate, tiny "model" or "scaffolding" table and joining it to your primary data. This approach is slightly more complex upfront but offers more flexibility, especially if you ever need to duplicate rows more than once (e.g., creating 3, 4, or more copies).
What is a Model Table?
A model table is just a simple, small table you create for the sole purpose of augmenting your primary dataset. To duplicate rows, our model table will have a single column and just two rows.
Step 1: Create Your Model Table
Open up Excel or a new Google Sheet. Create a single column named "PointID" and give it two rows with the values 1 and 2. Save this file (e.g., as "Model.xlsx").
Step 2: Join the Data in Tableau
Back in Tableau, connect to your primary data source as you normally would. Then, add a new connection to the model file you just created.
- Drag your primary data table to the canvas.
- Drag your model table to the canvas.
- The relationship editor will pop up, asking how to connect them. This is the crucial part. We need to create a relationship that matches every row from your primary table to every row in the model table. This is called a Cartesian join.
- In the "Edit Relationship" dialog, on the left, click "Create Relationship Calculation" and type the number
1. - On the right, do the same: click "Create Relationship Calculation" and type the number
1.
Your join clause will now be 1 = 1. This condition is always true, so it forces a relationship between every row of your main data and every row of your model table. Since your model table has two rows, every row in your original data will now be duplicated.
Using the Joined Data
Now, you have access to the [PointID] column from your model table. Just like in the union method, you can use this in calculated fields.
Using our "Point Type" example from before:
IF [PointID] = 1 THEN 'Start'
ELSEIF [PointID] = 2 THEN 'End'
ENDAnd your date calculation:
IF [PointID] = 1 THEN [Start Date]
ELSEIF [PointID] = 2 THEN [End Date]
ENDThis method achieves the same result as the self-union but is more scalable. If you needed to create four points for every row, you'd simply add rows 3 and 4 to your model table.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Method 3: The Custom SQL Approach (For More Technical Users)
If you're connecting to a database that supports Custom SQL (like PostgreSQL, SQL Server, etc.), you can handle the duplication at the query level. This can be more efficient because the data manipulation happens in the database before the results are even sent to Tableau.
You can use a UNION ALL query to achieve the same effect as a self-union.
Here’s how you’d set it up:
- Connect to your database in Tableau.
- Instead of dragging a table, drag "New Custom SQL" to the canvas.
- In the text box that appears, you’ll write a query.
Let’s say your table is named campaign_data. The SQL would look something like this:
SELECT
*,
'Start' AS R_Point_Type,
start_date AS R_Date
FROM
campaign_data
UNION ALL
SELECT
*,
'End' AS R_Point_Type,
end_date AS R_Date
FROM
campaign_dataThis query runs two SELECT statements and stacks the results. The first SELECT statement pulls all your original data and creates two new columns for the "Start" point. The second SELECT does the same for the "End" point. Now, when Tableau receives the data, it's already duplicated and contains the new fields you need for your visualization.
Choosing the Right Method for You
So, which method should you choose? Here’s a quick summary:
- Self-Union: The easiest and quickest for simple 2x duplication. It’s perfect when you're working with flat files like Excel or CSVs and don't want to manage extra files.
- Joining to a Model Table: The most flexible and scalable method. It's the best choice if you think you might need to create more than two copies of each row in the future.
- Custom SQL: Best for performance-conscious users connecting to a database. It shifts the workload to the database server and can provide more control and efficiency with large datasets.
Final Thoughts
Duplicating rows opens up a new level of creativity and analytical depth in Tableau, allowing you to build stunning, advanced visualizations. Whether you use the simple drag-and-drop union, the more flexible model join, or the powerful Custom SQL approach, you now have the tools to prepare your data for complex charting tasks.
While mastering techniques like these is rewarding, it also shows how much time can be spent wrestling with complex BI tools just to prepare data for visualization. With Graphed, we created a tool that lets you skip the tedious parts. Instead of manually joining or unioning data to build complex charts, you connect your data sources and tell our AI what you want to see using plain English. You get instant dashboards and real-time insights in seconds, not hours.
Related Articles
How to Create Facebook Ads API for Claude Code
Create a Meta Marketing API access token that never expires, using a system user, so Claude Code can pull Facebook ad reports and manage campaigns.
ClickHouse vs Postgres: When to Switch to Columnar
Comparing ClickHouse vs PostgreSQL means matching storage architecture to workload. Row storage wins for transactions. Columnar wins for scan-heavy analytics.
Google Ads for Orthodontists: Get More Booked Consults
Most orthodontic Google Ads campaigns waste money on low-intent searches. The problem is structure, not the platform.