Split Multiple Columns at the same time with Table Filter plugin

Lucas Messias December 12, 2023

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

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

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!

1 answer

1 accepted

4 votes
Answer accepted
Stiltsoft support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2023

Hi @Lucas Messias ,

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.  

Lucas Messias December 13, 2023

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.pngScreenshot 2023-12-13 at 16.09.47.pngScreenshot 2023-12-13 at 16.09.53.png

Stiltsoft support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2023

Hi @Lucas Messias ,

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', 'content'. But in the query you use 'Index', 'Header' and 'Content'. 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 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 as well. It is confidential, you may share your real data there and we'll be able to discuss an easier solution together.

Like Lucas Messias likes this
Lucas Messias December 13, 2023

You're right, "content" was wrong, but it's still not "exploding" the Index column.

Screenshot 2023-12-13 at 19.20.26.png

Stiltsoft support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 14, 2023

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

Like Lucas Messias likes this
Lucas Messias December 14, 2023

Worked perfectly! Thank you very much.

Like Stiltsoft support likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events