How to display multiple counts base on data from one table?
Asked by Leona:

Hi,

I have one big table that I want to display counts of:

* Total Number of Rows
* Count of records with status "OPEN"
* Calculate Percentage of Done

I was able to populate Table A with three macros (see screenshot). But this solution is heavy and takes a long time to load as I have many other macros on the page.

Any lightweight solution to look like Table B? Please note, I do not have TRANSWIKI.

Thank you.![project.png](https://community.atlassian.com/t5/image/serverpage/image-id/199443iC789C42904BEF237/image-size/large?v=v2&px=999 "project.png")


Answers:
author: Srinatha T
body: HI [@Leona](/t5/user/viewprofilepage/user-id/4947997) ,

Welcome to Atlassian community.

The below thread has some solution for you. It uses table transformer macro.

* [Table-Transformer-SQL-query-for-counting-values](https://community.atlassian.com/t5/Confluence-questions/Table-Transformer-SQL-query-for-counting-values/qaq-p/1970898)

Try that.

Thanks,

Srinath T

comments: author: Katerina Kovriga {Stiltsoft}
body: Hi [@Leona](/t5/user/viewprofilepage/user-id/4947997) ,

As [@Srinatha T](/t5/user/viewprofilepage/user-id/4686256) has kindly mentioned, the similar case can be achieved with one Jira Issues macro and one [Table Transformer](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Transformer+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro.

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

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

SELECT \*, 'Open'/'All'\*100 AS '% of Completion'  
FROM (SELECT SUM(IF(T1.'Status' = "To Do", 1, 0)) AS 'Open',  
SUM(IF('Status' IN ("To Do", "In Progress", "Done", "Answered"), 1, 0)) AS 'All'  
FROM T\*)

To get a vertical table instead of the horizontal one go to the "Settings" tab of the Table Transformer macro and check the "Transpose result table" option.

Hope this helps your case.


author: Leona
body: Thank you both for the quick response. The solution works beautifully.

I would use COUNT in the same way as SUM with the IF statement? When then would COUNT be a better solution than SUM? Thanks again.


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

What do you mean by a better solution? I don't think that the change of the function will improve your performance or smth.

By the way you can check all the available functions [here](https://docs.stiltsoft.com/display/public/TFAC/General+syntax+and+SQL+functions+available?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111).


author: Katerina Kovriga {Stiltsoft}
body: And pay attention to the obtained results:

SELECT SUM(IF(T1.'Status' = "To Do", 1, 0)) AS 'Open' FROM T1

equals to the

SELECT COUNT('Status' = "To Do") AS 'Open' FROM T1 WHERE T1.'Status' = "To Do"

The simple changing of the function's name can lead to incorrect results (your conditions won't be taken into consideration).

You can find more use cases [here](https://docs.stiltsoft.com/display/public/TFAC/Custom+Transformation+-+use+cases+with+advanced+SQL+queries?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111).


author: Leona
body: Hi Katerina, which of the two would have a better performance from the two examples you provided? COUNT vs SUM? I am learning lots, thanks.


author: Katerina Kovriga {Stiltsoft}
body: The performance depends more on the number of issues that are returned by your Jira Issues macro and the number of other macros on top.

Here we have one Table Transformer, so only one SQL query will be applied to the source table. And the SUM function just makes the initial SQL query look more neat and easy-to-read.


Tags: cloud

confluence-cloud