Table Transform: Separating Row Data Into Specific Columns
Asked by Cliff Wilson:

Hi All,

I'm admittedly a bit of a novice to SQL Query formatting with the table transform macro by Stiltsoft, and my google-fu hasn't turned up any viable solutions. So I'm hoping you fine folks can help!

**Goal:**   
Take data from Table 2 (Event) and list it out using the values (Month) from table 1 as the column headers, listing out events relevant to the month in the header below. I've included an image of what the result (Table 3) should look like.

![Table_Transform_Question.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/225788i0E298FBB10EEDFB5/image-size/large?v=v2&px=999 "Table_Transform_Question.JPG")

I've tried a few different ways to accomplish this, but have so far been unsuccessful in getting close to the desired result. I'm also not even certain that Table 1 is even necessary.

Any help would be greatly appreciated!


Answers:
author: Natalie Paramonova [Stiltsoft]
body: Hi [@Cliff Wilson](/t5/user/viewprofilepage/user-id/5077286)

We can suggest using the following options to get the table that is rather close to the desired variant.

**Option 1: Pivot Table + Table Transformer**

Here is what I have on my page in the Edit mode:  

![Wed 8-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/226395i15DE036F42D1EA9F/image-size/large?v=v2&px=999 "Wed 8-1.png")

Here is how the settings of the [Pivot Table](https://docs.stiltsoft.com/display/TFAC/How+to+use+Pivot+Table+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro look like:  

![Wed 8-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/226396i3E31329C528DDE25/image-size/large?v=v2&px=999 "Wed 8-2.png")  

![Wed 8-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/226397i2076E3F3D506A637/image-size/large?v=v2&px=999 "Wed 8-3.png")

The [Table Transformer](https://docs.stiltsoft.com/display/TFAC/How+to+use+Table+Transformer+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro is used to hide the unwanted columns and rename the required ones:

SELECT T1.'Literal of Event Jan' AS 'Jan',  
T1.'Literal of Event Feb' AS 'Feb',  
T1.'Literal of Event Mar' AS 'Mar'  
FROM T\*  

![Wed 8-4.png](https://community.atlassian.com/t5/image/serverpage/image-id/226398i86EC229EA9ECC291/image-size/large?v=v2&px=999 "Wed 8-4.png")

**Option 2: Table Transformer**

Here is what I have on my page in the Edit mode:  

![Wed 8-5.png](https://community.atlassian.com/t5/image/serverpage/image-id/226399i2EB202A0FCCC91C9/image-size/large?v=v2&px=999 "Wed 8-5.png")

And here is the required SQL query:

SELECT 'Month', 'Event'  
FROM (SELECT T1.'Month', CONCAT_VIEW_AGGR(FORMATWIKI(T1.'Event', "\\n")) AS 'Event' FROM T1 GROUP BY T1.'Month')  
PIVOT (FIRST('Event') for 'Month')  

![Wed 8-6.png](https://community.atlassian.com/t5/image/serverpage/image-id/226400iA07EA86AD278B635/image-size/large?v=v2&px=999 "Wed 8-6.png")

Hope this helps your case.

comments: author: Cliff Wilson
body: Genuinely want to thank you for taking the time to help me with this Natalie!

Apologies for the delayed response, the usual holiday season rush has gone into full effect for us haha.

I will check it out in more detail later this week, but my initial test page looks like this will do the trick nicely.


Tags: table-transformer

confluence-server

filter

server

stiltsoft

table

table-filter

table-filter-and-charts