Table Transformer - Add column B and C based on value in Column A for each matching row
Asked by nppani:

I am trying to Add two column values Column B and Column C based on value in Column A. How can I do that in the Table Transformer SQL

Example TABLE DATA

Col A Col B Col C

USA 10 20

CHINA 05 04

USA 30 20

USA 5 10

Select T1.'COL A',

IF (T1.'COL A' = "USA",1,0) THEN SUM(T1.'COL B', T1.'COL C') AS 'USA TOTAL',

IF (T1.'COL A' = "CHINA",1,0) THEN SUM(T1.'COL B', T1.'COL C') AS 'CHINA TOTAL',

FROM T\* GROUP BY T1.'COL A'

I might be wrong. Thanks for your time and help in advance.


Answers:
author: ? ?
body: ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ???


author: Katerina Kovriga {Stiltsoft}
body: Hi [@nppani](/t5/user/viewprofilepage/user-id/4097201)

You may use the following solution (the screenshots were taken for Cloud, so I use the [Table Toolbox](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Toolbox+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro to nest macros, for Server/Data Center you may wrap them directly):

![Fri 6-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/194097i80AC2AC8D7BB4DEB/image-size/large?v=v2&px=999 "Fri 6-1.png")

SELECT T1.'Col A',  
CASE WHEN T1.'Col A' LIKE "USA"  
THEN T1.'Col B' + T1.'Col C'  
END  
AS 'USA Total',  
CASE WHEN T1.'Col A' LIKE "China"  
THEN T1.'Col B' + T1.'Col C'  
END  
AS 'China Total'  
FROM T1

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

Then you may use the [Table Filter](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Filter+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro to count totals:

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

![Fri 6-4.png](https://community.atlassian.com/t5/image/serverpage/image-id/194100iFF815C18BF710B21/image-size/large?v=v2&px=999 "Fri 6-4.png")

Hope this helps your case.

comments: author: nppani
body: Thank you.


author: nppani
body: Unfortunately, I don't have that Macro in my Confluence 7.1.4 version.


author: Katerina Kovriga {Stiltsoft}
body: In the original question you've mentioned the Table Transformer twice - this is one of the macros provided with the Table Filter and Charts for Confluence app (along with Table Filter, Pivot Table, Chart from Table macros and many more).

Maybe I didn't get the question then and you mean smth else.


author: Katerina Kovriga {Stiltsoft}
body: Or you are on Server/Data Center and trying to find the Table Toolbox macro?

I've mentioned in the beginning of the answer that for Server/Data Center you place your source table inside the Table Transformer and then wrap your Table Transformer macro into the Table Filter macro directly on the page.

If you check the screenshots, you'll see that I use the Table Transformer and Table Filter macros, the Table Toolbox macro is just a shell for Cloud (Cloud users can't wrap macros directly one into another).


author: nppani
body: Thanks for your explanation Katerina. Let me explore and revert back.


Tags: confluence-cloud

table-transformer