ConradBI home

Home  /  How-to  /  Prepare your data

Joins, unions and pivots

Bring other tables into a prep and change its shape: add matching columns, stack rows, roll them up, or turn rows into columns and back.

The short version

  • Join Element adds another element's columns to the rows they match, by pairs of equal columns or by a Hu++ condition. Inner keeps only the matched rows, Left keeps them all.
  • Union puts other elements' rows under the result's rows, lined up by position, not by name.
  • Group By rolls rows up to one row per group, with counts, sums, averages, minimums and maximums.
  • Pivot turns the values of a column into columns. Unpivot turns columns back into rows.
  • They are steps like any other, and they run in SQL Server when every element they read is stored there.
Back to How-to guides
In this guide
  1. What it is
  2. Before you start
  3. Join another element
  4. Stack rows with a union
  5. Roll rows up with Group By
  6. Turn rows into columns with Pivot
  7. Turn columns into rows with Unpivot
  8. Where these steps run
  9. When something goes wrong
  10. Reference

What it is

The steps in Prepare data with steps work on one table. The five steps in this guide go further. Two bring in another element's data: Join Element adds columns, and Union adds rows. Three change the shape of the table: Group By rolls rows up, Pivot turns rows into columns, and Unpivot turns columns into rows.

They are ordinary steps of a Stepped Transform Prep. You add them in Step Management, set them in the Step Designer and check them on the Data tab, like the others.

If you know Excel, a join does the work of a VLOOKUP for a whole table at once, and Pivot does the work of a PivotTable's column area.

Before you start

You need Orders Prep, the Stepped Transform Prep from Prepare data with steps, with its Revenue column. Each example also uses an element of its own:

Example Element it reads Its columns
Join Products, from the Products sheet of Sales.xlsx Product Code, Product Name, Category
Union Orders 2025 and Orders 2026, one sheet of orders for each year The same as Orders
Unpivot Targets, a sheet of revenue targets Site Code, then one column per month: Jan to Dec

Process every element a step reads, so the preview has rows to show. Until you do, the preview treats that element as empty: an Inner join shows no rows, and a union adds none.

Join another element

Join Element adds the columns of another element to the rows of your table. Here, each order line gets its product's name and category from Products.

  1. Open Orders Prep and select its last step, so the join goes at the end.
  2. In Step Management, pick Join Element and click Add.
  3. Next to Join element, pick Products.
  4. Leave Join type at Inner for now.
  5. Leave the list below at Column mapping, and click Add condition.
  6. Under Result column, pick Product Code. Under Joined element column, pick Product Code.
  7. Open the Data tab. Each order line now ends with the columns of its product.

The joined columns go at the end. Products' own Product Code comes along as Product Code 2, because your table already has a Product Code. Remove it with a Remove Columns step.

Inner or Left

Join type Keeps
Inner Only the rows that match. An order line whose product code isn't in Products is dropped
Left Every row. An order line with no match gets empty product columns

A row that matches several rows of the joined element appears once for each of them. If Products lists a code twice, every order line with that code comes out twice, and its revenue counts twice. Make sure the joined element has one row per key, or join to a prep that removes the repeats first.

Column mapping

Each row of the mapping pairs a Result column with a Joined element column. With more than one row, every pair must be equal. Text matches without regard to capitals, and an empty value never matches anything. To take a pair out, click the ✕ at the end of its row.

A pair with a column left blank is ignored. With no complete pair at all, every row joins every row of the other element, so finish the mapping before you look at the rows.

Hu++ condition

Sometimes equal columns aren't enough. Pick Hu++ condition in place of Column mapping, and write a condition over both elements' columns in the code window. The pairs of rows that meet it join.

Name each column by the element it comes from: [Orders Prep].[Product Code] for your table's own columns, named after the prep, and [Products].[Product Code] for the joined element's. A column that only one of the two has can stand alone, like [Order Date].

Say a Price list element, read from Price list.pdf, holds each product's Price with the dates it is valid, Valid From and Valid To. This joins each order line to the price in force on its order date:

Hu++
[Orders Prep].[Product Code] = [Price list].[Product Code] AND [Order Date] >= [Valid From] AND [Order Date] <= [Valid To]
  • A condition that names no column of the joined element joins every row to every row of it.
  • A condition with a problem joins nothing until you fix it: an Inner join gives no rows, and a Left join keeps its rows with the joined columns empty. The problem shows under the code.
  • Switching between Column mapping and Hu++ condition keeps what you set in each.

For conditions in general, see the Hu++ guide.

Tip: For a large join that runs on your computer, use column mapping where you can. A condition is tested on every pair of rows, which takes longer as both tables grow. When both elements are in SQL Server, the server does the matching.

Stack rows with a union

Union puts the rows of one or more other elements under the rows of your table, like pasting one sheet under another. Say your orders come in one sheet a year, read by Orders 2025 and Orders 2026.

  1. Set the Source element of Orders Prep to Orders 2025.
  2. Add a Union step and drag it to the top of the step list, so every later step works on both years.
  3. Click Add element. A box called Element 1 appears.
  4. In Element 1, pick Orders 2026, and leave Mode at Select All.
  5. Read the note under it: "Its 13 column(s) go under the result's 13."
  6. Open the Data tab. The 2026 orders follow the 2025 ones.

Click Add element again for each further element. Their rows follow in the order listed.

With Mode at Select Columns, the element's columns are listed with a box to tick beside each. Tick the columns to take, and drag a ticked column up or down to change where it lines up; Alt+Up and Alt+Down move the one picked too. The note beside each column says which of your columns it goes under.

Rows line up by position

A union doesn't match columns by name. Each element's first column goes under your table's first column, its second under the second, and so on, and the result keeps your table's names. If Orders 2026 had Ship Date before Order Date, each date would land in the other's column.

To set the order yourself, pick Select Columns as the Mode. The element's columns are listed in their own order, all ticked, each with the column it goes under, as in "under Order Date". Untick a column to leave it out, and use the up and down arrows beside it to move it. A column you tick again goes to the end.

The columns of your table, as the step above the union leaves them, set the result:

  • An element's columns past the last of yours are left out. The designer marks each one "left out: no column to go under".
  • An element with fewer columns leaves the rest empty for its rows.
  • The line at the bottom of the designer lists the columns the union gives, with their types.

Types and repeats

When the columns at one position have different types, the result takes a type that holds them all: the widest number type when all are numbers, Date & Time when all are dates, and text otherwise. Dates turned into text read like 2026-03-14, and true and false read True and False.

A union keeps every row, repeats included. If the two sheets overlap, say both hold the last days of December, add a Remove Duplicate Rows step after the union.

Roll rows up with Group By

Group By gives one row for each combination of the columns you tick, with a column for each roll-up you add. Every other column goes. Here, the order lines become revenue and orders by site and channel.

Group By and Pivot reshape the whole table, so give each example a prep of its own and keep Orders Prep as it is.

  1. Create a Stepped Transform Prep with Orders Prep as its Source element, and add a Group By step.
  2. Under Group by, tick Group beside Site Code and Channel.
  3. Under Roll up, click Add roll-up. Pick Revenue under Column and Sum under Roll-up, and type Revenue under Name.
  4. Click Add roll-up again. Pick Order ID and Distinct count, and name it Orders.
  5. Open the Data tab: one row per site and channel, with Revenue and Orders beside them.

A roll-up with no name is named after what it does, like Sum of Revenue. The same column can be rolled up more than once, in different ways. To take a roll-up out, click the ✕ at the end of its row.

Roll-up Gives Type
Count How many values aren't empty Number
Distinct count How many different values there are Number
Sum The total Big Number for whole numbers, Decimal otherwise
Average The total divided by the count Decimal
Min, Max The smallest or the largest value The column's own

Good to know:

  • Empty values are left out of every roll-up. A group whose values are all empty gets a count of 0 and an empty sum.
  • Text groups without regard to capitals. Rows with an empty value in a group column form a group of their own.
  • A sum or average of a text column adds the values that read as numbers and skips the rest.
  • With nothing ticked under Group by, the whole table rolls up into one row.

You often don't need Group By: a fact adds up its measures for each visual on its own. Use it when the table itself should be smaller, such as a summary by site and channel.

Turn rows into columns with Pivot

Pivot turns the values of one column into columns of their own. With Channel pivoted and Revenue filling the new columns, each site gets one row with an Online column and a Store column.

Every column other than the two you pick groups the rows: one row for each combination of them. So first keep only the columns you want to group by.

  1. Create another Stepped Transform Prep with Orders Prep as its Source element. Add a Remove Other Columns step, and tick Keep beside Site Code, Channel and Revenue.
  2. Add a Pivot step.
  3. In Values become columns from, pick Channel.
  4. In Filled from, pick Revenue, and leave Rolled up as at Sum.
  5. Click Load values from the sample. The Values list fills with Online and Store, and a note says how many it found.
  6. Open the Data tab: one row per site, with its Online and Store revenue side by side.

Each new column is named by its value. A site with no Store orders gets an empty Store value. With Count as the roll-up, it gets 0. The roll-ups are the ones Group By has, listed above.

The values are kept on the step

Pivot doesn't look for new values each time it runs. It keeps its list, so the steps after it, and the elements that read the prep, know its columns in advance. A value that isn't listed is left out: if a Phone channel appears next month, its revenue is missing until you add it.

  • Load values replaces the list with every value the column has after the steps above, sorted.
  • Add value adds a row to type a value in. Edit any value in place, or click the ✕ beside it to take it out.
  • Values match as text, without regard to capitals or to spaces at the end.

Turn columns into rows with Unpivot

Unpivot does the reverse. Each column you tick becomes a row of its own, carrying the columns you didn't tick. It suits a sheet laid out for people to read, like Targets, with a column for every month:

Site Code Jan Feb … Dec
E01 12000 11500 … 15000
  1. Create a Stepped Transform Prep called Targets Prep, with Targets as its Source element.
  2. Add an Unpivot step, and tick Unpivot beside Jan to Dec.
  3. In Names in, type Month. In Values in, type Target.
  4. Open the Data tab: one row per site and month. E01's first row reads E01, Jan, 12000.

Good to know:

  • The two new columns start as Attribute and Value, and a blank name reads the same. A name one of your other columns already has gets a number after it.
  • The names column is text. The values column takes a type that holds every ticked column's values, by the same rule as a union.
  • An empty value makes no row. Tick Keep a row for an empty value to keep one, so a site with no target for March still gets a March row, with an empty Target.

Where these steps run

Join Element and Union read other elements. The whole prep runs in SQL Server only when its source and every element these steps read are stored there. If any of them isn't, the prep runs on the computer doing the processing. Group By, Pivot and Unpivot run in SQL Server whenever the rest of the prep does. Prepare data with steps has the details.

When something goes wrong

What you see What to do
"[Product Code] could be any of [Orders Prep].[Product Code], [Products].[Product Code]: say which element's." Both elements have that column. Write the element in front of it: [Products].[Product Code]
An Inner join gives no rows Process the joined element. In Hu++ condition mode, fix the problem shown under the code. Then check that the keys look alike in both elements: a space at the start of a key stops a match, so try a Trim Whitespace step
The join gives more rows than your table had The joined element has a key more than once. Remove the repeats, or match on more columns
Every row joins every row The mapping has no complete pair, or the condition names no column of the joined element
A column called Product Code 2 appears Both elements had a Product Code. Remove the copy with Remove Columns
"No elements are listed, so the step adds no rows." Click Add element in the Union step
"Element 1 has no element picked." Pick an element in that box
"'Orders 2026' has no columns checked, so it adds no rows." Tick its columns, or set its Mode to Select All
"'Orders 2026' has no column 'Ship Date' any more: its place stays empty." The element changed. Untick the column, or tick the one that replaced it
"left out: no column to go under" beside a column The element has more columns than your table. Untick it, or move it up in place of another
A union puts dates in the wrong columns Columns line up by position. Use Select Columns to put them in order
"The sample has no values in that column: process the source, or add the values by hand." Process the source, or click Add value and type the values
A pivot is missing a value, such as a new channel Add it to the Values list. A value that isn't listed is left out
A pivot gives more rows than you expected The columns you didn't pick group the rows. Remove them with Remove Other Columns first
An unpivot has fewer rows than you expected The missing ones had empty values. Tick Keep a row for an empty value

Reference

Step You set It gives
Join Element Join element and Join type (Inner or Left). Then pairs of Result column and Joined element column under Column mapping, or a Hu++ condition Your columns, then the joined element's
Union Add element, then for each element its Mode: Select All or Select Columns Your columns, with the elements' rows under yours
Group By The Group columns, then each roll-up's Column, Roll-up and Name The group columns, then one column per roll-up
Pivot Values become columns from, Filled from, Rolled up as, and the Values The other columns, then one column per value
Unpivot The columns to Unpivot, Names in, Values in and Keep a row for an empty value The other columns, then the names and the values

Missing something?

Tell us what you were trying to do and what this guide didn't answer. We update it with every release.

Write to us

What changed in this guide

  • November 21, 2026: Updated for 1.2.59: Load values reads every row, and only a space at the start of a key stops a join.
  • October 31, 2026: First edition, written for ConradBI 1.2.52.