# Pivot/unstack/crosstab

**URL:** <https://community.easymorph.com/t/pivot-unstack-crosstab/3253>\
**Category:** General Q&A\
**Created:** [December 14, 2021, 5:38pm UTC](https://community.easymorph.com/t/pivot-unstack-crosstab/3253 "2021-12-14T17:38:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rick](https://community.easymorph.com/letter_avatar_proxy/v4/letter/r/9f8e36/32.png) [@Rick](https://community.easymorph.com/u/Rick)\
**Post date:** [December 14, 2021, 5:38pm UTC](https://community.easymorph.com/t/pivot-unstack-crosstab/3253/1 "2021-12-14T17:38:12Z")

</div>

Hi all, I'm trying to transform a table that has a list of values into rows of values. The source table has five columns. The first column is a "TestID" and for each "TestID" there are ten rows of data that are related.  
The transformed data should have the "TestID" in the first column but only one value and the 10 related values in the adjacent columns. I've seen this operation called unstack in Excel or Pivot. I tried the pivot function in EasyMorph but each new value is on the next row. I've been able to recreate the function using a crosstab query in MS Access.

 ![image](https://community.easymorph.com/uploads/default/original/2X/5/5241656a2d48dcf79184fe443f3e709014f4e0d8.png)

Result:

 ![image](https://community.easymorph.com/uploads/default/original/2X/d/d7c0157a3a6c67c597593819db2e5372d3f6bfaf.png)

What I want:

 ![image](https://community.easymorph.com/uploads/default/original/2X/6/6229292f97b8666ebca68ee872d696c93045985a.png)

---

<div class="post-metadata">

**Author:** ![roberto](https://community.easymorph.com/user_avatar/community.easymorph.com/roberto/32/8595_2.png) [@roberto](https://community.easymorph.com/u/roberto)\
**Post date:** [December 14, 2021, 7:29pm UTC](https://community.easymorph.com/t/pivot-unstack-crosstab/3253/2 "2021-12-14T19:29:29Z")

</div>

Hey Rick,

In this case, you have to Unpivot once, delete a column that gets created with the unpivot, and then Pivot:

 ![image](https://community.easymorph.com/uploads/default/original/2X/a/a2343e9ec5940a89395602c8270479c0de269100.png)

Here you can download this sample project: [Vertical to horizontal.morph](https://community.easymorph.com/uploads/short-url/r7at9R3pNvlk4wLZqaBnzNlPWOg.morph) (4.1 KB)

When pivoting, the columns are automatically ordered by column name (from A to Z). If you want to keep the original/specific order in the columns, check out this article:

> [@Pivot Columns in Order](https://community.easymorph.com/t/pivot-columns-in-order/2436):
>
> Hello, i would like to pivot the data according to order. So RowNo 1 = Column1, RowNo 2= Column 2 ... At the moment the columns are unsorted. It is not clear to me which order is used. Is that possible? Wasn't there something like aggregate, groups ... don't know at the Moment, how it works relaxed [grafik] [pivot\_in\_order.morph](https://community.easymorph.com/uploads/short-url/60iOCrWoaWJKRo5rWfcgtbVDMCR.morph) (2.2 KB) [data.dset](https://community.easymorph.com/uploads/short-url/9FCwSbuE5cfBYodTEw1XpwSUeNP.dset) (526 Bytes) Regards, Adrian

Regards,

Roberto

---

<div class="post-metadata">

**Author:** ![Rick](https://community.easymorph.com/letter_avatar_proxy/v4/letter/r/9f8e36/32.png) [@Rick](https://community.easymorph.com/u/Rick)\
**Post date:** [December 14, 2021, 10:22pm UTC](https://community.easymorph.com/t/pivot-unstack-crosstab/3253/3 "2021-12-14T22:22:24Z")

</div>

Thanks for the help. I actually got what I want by deleting one of the columns (StatName) in the source before the pivot. I used the "ColumnNumber" as the column Labels to get them in the order that I wanted.

 ![image](https://community.easymorph.com/uploads/default/original/2X/a/a3684f769ea45edd16e15364e2f466d17ed99b14.png)

---

<div class="post-metadata">

**Author:** ![dgudkov](https://community.easymorph.com/user_avatar/community.easymorph.com/dgudkov/32/5_2.png) [@dgudkov](https://community.easymorph.com/u/dgudkov)\
**Post date:** [December 14, 2021, 10:44pm UTC](https://community.easymorph.com/t/pivot-unstack-crosstab/3253/4 "2021-12-14T22:44:40Z")

</div>

Now you can use the ["Rename by lookup" action](https://help.easymorph.com/doku.php?id=transformations:lookuprename) to rename the number-named columns to their original names.
