Split Multiple Columns at the same time with Table Filter plugin
Asked by Lucas Messias:

Hey, I'm trying to split data from an ARRAY into rows for the following table:

![Screenshot 2023-12-12 at 16.46.52.png](/t5/image/serverpage/image-id/296460iF1073578EA99CA8E/image-size/large?v=v2&px=999 "Screenshot 2023-12-12 at 16.46.52.png")

So I've tried this Table Transform macro:

```
SEARCH / AS @a EX('content'->split(","), 'Index'->split(",")) /
RETURN(@a->'Header' AS 'Header', _ AS 'content', _ AS 'Index') FROM T1
```

But it isn't working, that is what I'm getting:

![Screenshot 2023-12-12 at 16.52.36.png](/t5/image/serverpage/image-id/296461i2B4AF9D7BAE2EAA9/image-size/large?v=v2&px=999 "Screenshot 2023-12-12 at 16.52.36.png")

My end goal is to split **content** and **Index** columns simultaneously, so I can later PIVOT this table to make the **Header** column become the table header, **Index** would be the group by operator and **content** the main row values (something like group by Index MAX(content)).

Is it possible to do?

Thank you!


Answers:
author: Stiltsoft support
body: Hi [@Lucas Messias](/t5/user/viewprofilepage/user-id/5385043) ,

You may try the following SQL query:

SET @indexes = (SELECT SUM('Index'+",")-\>split(",") FROM T1);

SEARCH / AS @a EX('Content'-\>split(",")) /  
RETURN(@a-\>'Header' AS 'Header', _ AS 'Content', @indexes-\>shift() AS 'Index')  
FROM T1

Please note that the number of comma separated strings within the 'Content' cells should match the number of indexes.

So, your tabular array is not best practice at all, there could be errors due to personal mistakes. It is always better to create proper tables firsthand (a separate row for each entry): you'll be able to filter out empty cells and group your tables easily.

comments: author: Lucas Messias
body: Hey, thank you for your quick response. I do agree that using ARRAY may not be the most ideal solution, but it was the only workaround I found for achieving a specific functionality.

Basically, I aim to implement a Dropdown menu that dynamically alters the columns of a table based on the user's selection. Together with that, I need to merge different tables as well. So, for example, the user choose "Preset 1" option on the dropdown, this will make the macro merge table 1 and 2 and generate the new header. Then he chose "Preset 2" and now the merge is between table 1 and 3. Consequently, I had to use ARRAY to pivot and unpivot the data, facilitating changes to the header. I'm wondering if there might be an alternative approach to achieve this. What do you think?

Unfortunately, the provided solution is not returning rows, even though both Index and Content have the same number of commas.

I appreciate any insights or suggestions you may have regarding this issue.

Thank you.

Screenshots of my current Table Toolbox:

![Screenshot 2023-12-13 at 16.09.38.png](https://community.atlassian.com/t5/image/serverpage/image-id/296690i2CFA452FFAC65A8D/image-size/large?v=v2&px=999 "Screenshot 2023-12-13 at 16.09.38.png")![Screenshot 2023-12-13 at 16.09.47.png](https://community.atlassian.com/t5/image/serverpage/image-id/296691i31EF32F539C4AA7F/image-size/large?v=v2&px=999 "Screenshot 2023-12-13 at 16.09.47.png")![Screenshot 2023-12-13 at 16.09.53.png](https://community.atlassian.com/t5/image/serverpage/image-id/296692i394FFB14848B0F44/image-size/large?v=v2&px=999 "Screenshot 2023-12-13 at 16.09.53.png")


author: Stiltsoft support
body: Hi [@Lucas Messias](/t5/user/viewprofilepage/user-id/5385043) ,

The provided query is a working one, please check the names of your columns.

As I see on the first screenshot, you have 'Index', 'Header', '**c** ontent'. But in the query you use 'Index', 'Header' and '**C**ontent'. Uppercase and lowercase letters used for the columns' names are treated differently.

What concerns the idea in general, it seems rather complex. Maybe the easier way will be to combine (merge) the 2rd, 3rd, 4th, etc. tables firsthand and wrap the result table in the Table Filter macro. The user may set a filter and then this filtered table will be merged with the first table.

Or maybe is better to use the [Table Spreadsheet](https://docs.stiltsoft.com/tfac/cloud/how-to-use-table-spreadsheet-macro-83100938.html?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro where you can use Excel-like filters, pivot tables and can refer to different cells from the current or other sheets and create different views of the same table.

You may reach to our [support portal](https://stiltsoft.atlassian.net/servicedesk/customer/portal/14) as well. It is confidential, you may share your real data there and we'll be able to discuss an easier solution together.


author: Lucas Messias
body: You're right, "content" was wrong, but it's still not "exploding" the Index column.

![Screenshot 2023-12-13 at 19.20.26.png](https://community.atlassian.com/t5/image/serverpage/image-id/296729i3DA0C303FB43E151/image-size/large?v=v2&px=999 "Screenshot 2023-12-13 at 19.20.26.png")


author: Stiltsoft support
body: Sorry, my bad: tested the query on Data Center and for Cloud it works slightly differently.

Please use the following SQL:

SET @indexes = (SELECT SUM(**TEXT**('Index')+",")-\>split(",") FROM T1);

SEARCH / AS @a EX('Content'-\>split(",")) /  
RETURN(@a-\>'Header' AS 'Header', _ AS 'Content', @indexes-\>shift() AS 'Index')  
FROM T1


author: Lucas Messias
body: Worked perfectly! Thank you very much.


Tags: cloud

confluence-cloud

filter

table

table-filter

table-filter-and-charts

table-transformer