Merging columns to count instructors
Asked by Bruce Fratto:

I'm trying to count then number of instructors for a course. Here's the table structure:

**Trainer 1 Trainer 2**

Bob Sonya

Randy Tom

Sonya Randy

There are 2 trainers for each course. They could be in either column. I've merged the cells using SQL but now they are all in 1 cell and I can't count them.

**Desired output**

Bob - 1

Randy - 2

Sonya - 2

Tom - 1


Answers:
author: Stiltsoft support
body: Hi [@Bruce Fratto](/t5/user/viewprofilepage/user-id/701135) ,

As you've mentioned SQL queries, I assume you use our [Table Filter and Charts for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-and-charts-for-confluence?tab=overview&hosting=datacenter&utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) app and its [Table Transformer](https://docs.stiltsoft.com/tfac/dc-server/how-to-use-table-transformer-macro-42241552.html?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro.

If this is the case, you may use the following structure:

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

Here I copied my test table twice for simplicity but you may reuse it via the [Table Excerpt/Table Excerpt Include](https://docs.stiltsoft.com/tfac/dc-server/how-to-use-table-excerpt-and-table-excerpt-include-macros-42241623.html?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macros. In this case, you'll have only one source table, all the updates will be passed to its copy automatically.

In the internal Table Transformer macros we aggregate our data:

SELECT "Count 1" AS 'Name',  
'Trainer 1' FROM T1  
PIVOT (COUNT('Trainer 1') for 'Trainer 1')

Then we go to the Settings tab and check the "Transpose result table" option.

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

The same goes for the second internal Table Transformer macro:

SELECT "Count 2" AS 'Name',  
'Trainer 2' FROM T1  
PIVOT (COUNT('Trainer 2') for 'Trainer 2')

The "Transpose result table" option is also checked.

Then we move to the middle Table Transformer macro and use the following SQL query:

SELECT 'Name',  
CASE WHEN 'Count 1' IS NULL  
THEN "0"  
ELSE 'Count 1'  
END  
AS 'Count 1',  
CASE WHEN 'Count 2' IS NULL  
THEN "0"  
ELSE 'Count 2'  
END  
AS 'Count 2'  
FROM  
(SELECT \* FROM T1 OUTER JOIN T2 ON T1.'Name' = T2.'Name')

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

Now we go to the external Table Transformer macro and perform the result calculations:

SELECT \*,  
'Count 1' + 'Count 2' AS 'Total Count'  
FROM T1

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

Hope it helps your case.

comments: author: Bruce Fratto
body: Your tag "Rising Star" is misleading... Should read "Rock Star". There are many lessons learned here.

- You know what you are doing

- I should have asked for help hours ago

- This answer is way above my pay grade

- I am obviously higly impressed and appreciative of your quick response and it works like a charm!

Thank you!


Tags: confluence-server

filter

ms-excel

server

table