Merge tables from table transformer macro
Asked by Esteban Borja Lopez:

Hi all,

im struggling to create a merge 2 tables where 1 of them is a result of a table transformer macro with the goal of getting automatic updates and avoid any manual intervention. See below the case:

1. Fixed table

* ![Screenshot 2022-06-09 at 09.54.57.png](/t5/image/serverpage/image-id/201220iA7026C3E15FCF320/image-dimensions/57x211?v=v2 "Screenshot 2022-06-09 at 09.54.57.png")

2. Macro table ("KPI" data)

* ![Screenshot 2022-06-09 at 09.56.44.png](/t5/image/serverpage/image-id/201221i91721D5B3CEE7D48/image-dimensions/221x196?v=v2 "Screenshot 2022-06-09 at 09.56.44.png")

* ![Screenshot 2022-06-09 at 09.58.11.png](/t5/image/serverpage/image-id/201223i65D81DD73DF6BC01/image-dimensions/285x153?v=v2 "Screenshot 2022-06-09 at 09.58.11.png")

I've tried adding both tables to a new table transformer macro where do the merge (using default SQL config), this is the actual result:

* ![Screenshot 2022-06-09 at 10.02.08.png](/t5/image/serverpage/image-id/201225iBB4D0013DFCE3DD6/image-dimensions/291x474?v=v2 "Screenshot 2022-06-09 at 10.02.08.png")
* ++![Screenshot 2022-06-09 at 10.02.55.png](/t5/image/serverpage/image-id/201226iB9D0DA8D07DB285E/image-dimensions/319x172?v=v2 "Screenshot 2022-06-09 at 10.02.55.png")++
* ++![Screenshot 2022-06-09 at 10.05.03.png](/t5/image/serverpage/image-id/201227i638E6E66D9BB528D/image-dimensions/128x232?v=v2 "Screenshot 2022-06-09 at 10.05.03.png")++

++Desired result++

* ![Screenshot 2022-06-09 at 10.00.08.png](/t5/image/serverpage/image-id/201224i7FD10324EF2AC06F/image-size/large?v=v2&px=999 "Screenshot 2022-06-09 at 10.00.08.png")

where "100" is somehow automatically fetched from the table transformer macro. Each month will have a specific table transformer result so the "Response Times" column name should be changed to "01", "02", ... to do the proper mapping, just did it this way for example purposes.

I assume it's about SQL code to the the proper join and columns mapping, but were not able to find a workable solution for this so far.

Thanks in advance for your attention and help!

Regards,

Esteban


Answers:
author: Katerina Kovriga {Stiltsoft}
body: Hi [@Esteban Borja Lopez](/t5/user/viewprofilepage/user-id/589696) ,

These two tables can't be merged together in a proper way. The first **Merge preset** that you choose merges the tables with similar headers:

\|Col 1 \|Col 2 \|

\|A \|12 \|

\|B \|14 \|

+

\|Col 1 \|Col 2 \|

\|C \|23 \|

\|D \|44 \|

=

\|Col 1 \|Col 2 \|

\|A \|12 \|

\|B \|14 \|

\|C \|23 \|

\|D \|44 \|

The second **Look Up preset** merges tables by the unique column.

For example, in your case it's Month.

\|Month \|Col 2 \|

\|01 \|Some info 01\|

\|02 \|Some info 02\|

\|03 \|Some info 02\|

\|04 \|Some info 02\|

So to add the KPI you need to generate one big or several small tables with the format:

\|Month \|KPI \|

\|02 \|100\|

Then the result will be as following:

\|Month \|Col 2 \|KPI \|

\|01 \|Some info 01\| \|

\|02 \|Some info 02\|100\|

\|03 \|Some info 02\| \|

\|04 \|Some info 02\| \|

Hope I was able to clarify the case a little bit for you.

comments: author: Esteban Borja Lopez
body: Hi [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) , thanks a lot for your response, always a pleasure seeing your name involved :)

I've modified the macro SQL to generate same header as the fixed table

![Screenshot 2022-06-09 at 11.15.17.png](https://community.atlassian.com/t5/image/serverpage/image-id/201256i77DD7677721937E5/image-dimensions/84x241?v=v2 "Screenshot 2022-06-09 at 11.15.17.png")

Tried adding an additional macro for month 02 and set the following SQL on the main table transformer

SELECT  
\*  
FROM T1 JOIN T2 ON T1.'Month' = T2.'Month'

++Result++

![Screenshot 2022-06-09 at 11.22.18.png](https://community.atlassian.com/t5/image/serverpage/image-id/201258i4D52802FF49D6ABA/image-size/large?v=v2&px=999 "Screenshot 2022-06-09 at 11.22.18.png")

so it's working for 1 table but I would need to tune the SQL to map T1.'Month' to each 'Month' column from the additional 11 tables... any hint on how to modify above SQL to do something like "***FROM T1 JOIN T\* ON T1.'Month' = T\*.'Month'***"?

Regards,


author: Katerina Kovriga {Stiltsoft}
body: It seems that the case is more simple - don't change anything in the SQL query and just choose the Look Up preset.

Here is my example with one stable table (and it doesn't require the KPI column, the Month column is enough) and three mini-tables (let's pretend that they are generated by other internal Table Transformers):

![Thu 3-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/201266i3E909BC4431A5583/image-size/large?v=v2&px=999 "Thu 3-1.png")

Then I choose the Look Up preset and the common Month column is shown for me to choose by default:

![Thu 3-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/201267i0F6237DB9B228844/image-size/large?v=v2&px=999 "Thu 3-2.png")

And here is the result:

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


author: Esteban Borja Lopez
body: It worked like a charm:

![Screenshot 2022-06-09 at 12.28.22.png](https://community.atlassian.com/t5/image/serverpage/image-id/201272iDAB40F3AB5DDDA13/image-dimensions/346x263?v=v2 "Screenshot 2022-06-09 at 12.28.22.png")

And as for my final goal as well:

![Screenshot 2022-06-09 at 12.35.06.png](https://community.atlassian.com/t5/image/serverpage/image-id/201273i94481C212C2AB4EF/image-size/large?v=v2&px=999 "Screenshot 2022-06-09 at 12.35.06.png")

So all working as desired and no manual work other than initial config.

You rock [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) :)


author: Katerina Kovriga {Stiltsoft}
body: Thank you!

I'll pass your feedback about the app to the team. :)


Tags: confluence-server

server