Model Basics – Unpivot

|

The unpivot function converts a wide short table into a narrower but longer table. The primary purpose of using this function is to convert a grid of numbers into a single column.

For example this table:

can be unpivoted if ‘Common’ is a common field and ‘A’, ‘B’, ‘C’ are all data fields:

For another example with a table with multiple rows in the header:

This information table has just three rows of data and seven columns, organized by quarter. When ‘unpivoted’ into a single column of data, looks like this:

As you can see, the first two columns have not been changed. The next three columns: Date 1 to Date 3 contain values that were in the original tables column header. Finally, the last column – Units – contains all the values that were in the original grid.

See this post for more on how this unpivoted table could be used in a view.

The unpivot designer looks like this:

Upon opening, the ‘Available Fields’ dotted box at the top left contains all table fields. Fields dragged to ‘Common Fields’ are not unpivoted but are duplicated as needed. The first two columns have been moved here. Fields dragged to ‘Data Fields’ undergo unpivoting, creating a new row for each added field. It’s important to note that the presence of multilevel headers leads to the addition of an equivalent number of columns. In the provided example, the original table featured a header with three rows, resulting in the unpivoted table adding three columns.

This post has demonstrated unpivoting and has highlighted how Oasis makes easy the inclusion of this function into a model.

Back to Exploring

trudain.com | All content copyright (c) 2022-2024