How to count each status of the status macro

J S July 20, 2017

Hey,

I'm trying to summarize all the of the status information given by the status macro in one graph. To do this I need the total count of each possible status. Is there any way to do this because i didnt find any macro that would be able to this and counting it manually would take too much time in the long run.

Many thanks in advance!

 

3 answers

1 accepted

1 vote
Answer accepted
Andrey Khaneev _StiltSoft_
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.
July 20, 2017

Hi,

Dou you want to count statuses in a single page? How do you place them (maybe in a table or Page Properties Report macro)?

J S July 20, 2017

Hey,

i want to count the statuses of several pages. On the "main" page above I'm using the Page Properties Report Macro (+ labels) right now but I want to change it to a table, so that i can write the status name in one column and the count into another one.

My goal is to use the chart macro to display the information in a graph.

Andrey Khaneev _StiltSoft_
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.
July 20, 2017

Then you can use Pivot Table macro to count each status in a table or PPR macro. And you can use Chart from Table macro to visualize it.

Both macro are shipped with Table Filter and Charts add-on.

Andrey Khaneev _StiltSoft_
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.
July 20, 2017

Here is the video with your case.

Like Andriy Kech likes this
J S July 20, 2017

It worked. Thanks a lot!

Andrey Khaneev _StiltSoft_
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.
July 20, 2017

You are welcome!

1 vote
Stephen Deutsch
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.
July 20, 2017

If you want to simply count all statuses in a single page (no filtering required), then you could simply install this simple user macro that puts a count of all same statuses (i.e. if the text is different, then it counts as unique) on a page in a table:

## @noparams
<table>
<tbody id="status-table">
<tr>
<th>Status</th>
<th>Count</th>
</tr>
</tbody>
</table>
<script>
AJS.toInit(function() {
var statusTable = jQuery("#status-table");
var statusMacros = {};
jQuery(".status-macro").each(function() {
if (statusMacros.hasOwnProperty(this.outerHTML)) {
statusMacros[this.outerHTML] += 1;
} else {
statusMacros[this.outerHTML] = 1;
}
});
Object.keys(statusMacros).forEach(function(key) {
statusTable.append('<tr><td class="confluenceTd">' + key + '</td><td class="confluenceTd"><p>' + statusMacros[key] + '</p></td></tr>')
});
});
</script>

 

Stephen Deutsch
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.
July 20, 2017

Ah, I think this is what you're looking for, but it renders the table on the front-end, so it wouldn't be able to be inserted into the graph macro... let me see if I can figure out how to do it on the back-end.

Stephen Deutsch
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.
July 20, 2017

In case someone wants to try it without installing a plugin, here's a user macro that should work inside the chart macro (but it won't be displayed properly until you save the page):

## @noparams
#set ( $container = {} )
#set( $contentBody = $content.bodyAsString )
#foreach ( $part in $contentBody.split('(?=<ac:structured-macro)|(?<=\/ac:structured-macro>)') )
#if ( $part.contains('ac:name="status"') )
#set ( $status = $part.replaceAll(' ac:macro-id=".{36}"', '') )
#set ( $statusCount = false )
#set ( $statusCount = $container.get($status) )
#if ( $statusCount )
#set ( $statusCount = $statusCount + 1 )
#set ( $void = $container.put($status, $statusCount) )
#else
#set ( $void = $container.put($status, 1) )
#end
#end
#end
<table>
<tbody>
<tr>
<th>Status</th>
<th>Count</th>
</tr>
#foreach ( $status in $container.keySet() )
<tr>
<td>$status</td>
<td>$container.get($status)</td>
</tr>
#end
</tbody>
</table>

 

A K August 31, 2017

that looks great, I'm trying to include this into my page right now.

I'm just a bit lost on where exactly to include the code block?

My diagram area looks somewhat like this (simplified):

chart_makro.JPG

Stephen Deutsch
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.
August 31, 2017

Hi AK,

you seem a little bit confused about the effects of the macro. What it does is count the status macros on the entirety of the page, so you shouldn't include the statuses within the diagram macro.

First of all, you will have to include the code in a user macro (give it a name):

https://confluence.atlassian.com/doc/writing-user-macros-4485.html

Then you have to include the macro with the name that you defined inside of the diagram macro, and this combination will generate a chart with a count of each status macro. Please make sure you use the 2nd one (the one from the reply, not the main answer).

Stephen Deutsch
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.
August 31, 2017

Please note that this only works for Server, as you can't use user macros in Confluence Cloud, but I'm working on building this functionality into a Confluence Cloud app.

A K September 1, 2017

Great, thanks for clarifying. I was looking for a way to do it without having to write a macro (it's hard to get that past our administration). Will see

Victoria Pooley May 2, 2018

@Stephen Deutsch if you're not a Global Admin and can't develop a User Macro as you've suggested above (and many others have also - including https://stiltsoft.com/blog/2017/09/counting-statuses-dates-tasks-and-other-items-in-confluence/), and the organisation doesn't appear to have added Pivot Macro to our environment - is there any other way to count status modules on a page. I've searched as many blogs and pages to find another way. My administrator here is slammed and won't be able to help me. 

Allan Ngo June 20, 2018

+1 to @Victoria Pooley
This would be a great standard feature to be able to report on this or pivot without additional plugins would be great.

Peter Florijn February 21, 2019

@Stephen Deutsch 

I try to use the status count in a Chart Macro.

The user macro version 1 is working OK.

The backend version is not giving the same results. (your second answer from 20 July)

It is not grouping by status but shows every status with Count 1.

Any suggestions ?

TIA

avinashp June 11, 2019

@Stephen Deutsch  - your macro is not grouping, can you check if you have time

Stephen Deutsch
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.
June 11, 2019

Something might have changed in recent versions, I'll check soon and update

avinashp June 17, 2019

@Stephen Deutsch  Did you get a chance to look into it ? 

Stephen Deutsch
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.
September 7, 2019

Sorry it's so late, but I just edited the answer; it's now fixed (there was a space in the wrong place).

Peter Florijn October 18, 2019

@Stephen Deutsch 

Thanks for the fix. It's working OK now.

Little observation, if you enter the status code text it appears always as uppercase, but you can enter it in upper and lowercase. If you mix those the count is not correct and will show a count for the uppercase status and the lowercase one.

Sirbulescu Alexandra-Elena August 8, 2022

How can I should do if I want to count statuses from more page?

Like Laurie Sciutti likes this
0 votes
Sirbulescu Alexandra-Elena July 19, 2022

How can I should do if I want to count statuses from more page? @Stephen Deutsch 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events