Calculating the Number of Values Selected in a List
Scenario
You've built a form, and you'd like to count some of the user's entries in a Adding a dropdown list of users macro.
Result
N/A
Recipe
Apps | Reporting for Confluence Server & Data Center, Scaffolding for Confluence Server |
---|---|
Level | Intermediate |
Estimated time | 10 minutes |
Macros | Report Eval, Report Variable, Text Filter |
Suppliers | Stats On Supplier, Variable Supplier |
Storage format
You can copy and paste this code into the Confluence Source Editor:
<h3>Description:</h3>
<p>In this example, We'll calculate how many times users enter a value in a list.</p>
<ac:structured-macro ac:macro-id="39e7e0b6-36e0-40b1-8b24-5b7d900c3c15" ac:name="table-data" ac:schema-version="1">
<ac:parameter ac:name="name">failpass</ac:parameter>
<ac:rich-text-body>
<table class="wrapped">
<colgroup>
<col/>
<col/>
</colgroup>
<tbody>
<tr>
<th>Test</th>
<th>Result</th>
</tr>
<tr>
<td>
<div class="content-wrapper">
<ac:structured-macro ac:macro-id="e3381d17-e691-4128-96c5-7b38318a5e0a" ac:name="text-data" ac:schema-version="1">
<ac:parameter ac:name="name">TestNo</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
</div>
</td>
<td>
<div class="content-wrapper">
<ac:structured-macro ac:macro-id="1f5606d4-44bd-4de0-ac2f-4ea0c47ff54b" ac:name="list-data" ac:schema-version="1">
<ac:parameter ac:name="name">result</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:macro-id="70fcee09-f455-4ca3-a0fa-73f2e7802e90" ac:name="list-option" ac:schema-version="1">
<ac:parameter ac:name="value">fail</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="941b9b63-0078-4152-a189-3bd5bb8cf887" ac:name="list-option" ac:schema-version="1">
<ac:parameter ac:name="value">pass</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
</div>
</td>
</tr>
</tbody>
</table>
<p>
<br/>
</p>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<h3>Result: </h3>
<ac:structured-macro ac:macro-id="624344f6-6209-4332-99ca-def940c42760" ac:name="report-variable" ac:schema-version="1">
<ac:parameter ac:name="name">totalFail</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:macro-id="62b2ec16-ca70-4b7d-9f88-1feaa6d2154b" ac:name="local-reporter" ac:schema-version="1">
<ac:parameter ac:name="">data:failpass</ac:parameter>
<ac:rich-text-body>
<p>
<ac:structured-macro ac:macro-id="48b25b58-d73e-4606-af81-33711463b548" ac:name="text-filter" ac:schema-version="1">
<ac:parameter ac:name="value">fail</ac:parameter>
<ac:parameter ac:name="">data:result</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="febe95bf-28ec-4087-8ccb-299309cc6772" ac:name="report-variable" ac:schema-version="1">
<ac:parameter ac:name="name">totalPass</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:macro-id="2e300fe0-3c48-4b9c-8c86-0e1bd888ea50" ac:name="local-reporter" ac:schema-version="1">
<ac:parameter ac:name="">data:failpass</ac:parameter>
<ac:rich-text-body>
<p>
<ac:structured-macro ac:macro-id="db1dbc43-1a65-45ad-8b42-87a4399771bf" ac:name="text-filter" ac:schema-version="1">
<ac:parameter ac:name="value">pass</ac:parameter>
<ac:parameter ac:name="">data:result</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
<p>Number of Fails: <ac:structured-macro ac:macro-id="ea2843fe-0a85-4b6d-ad3f-6a2bda75eb96" ac:name="report-info" ac:schema-version="1">
<ac:parameter ac:name="">variable:totalFail>size</ac:parameter>
</ac:structured-macro>
</p>
<p>Number of Passes: <ac:structured-macro ac:macro-id="d9281b6c-5984-4bac-a8ce-bc1dec827601" ac:name="report-info" ac:schema-version="1">
<ac:parameter ac:name="">variable:totalPass>size</ac:parameter>
</ac:structured-macro>
</p>
<p>The total number of results is: </p>
<ac:structured-macro ac:macro-id="9a2a7719-ab6f-4642-9f83-c90c0f5ea469" ac:name="report-eval" ac:schema-version="1">
<ac:parameter ac:name="format">#</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:parameter ac:name="">totalresult</ac:parameter>
<ac:plain-text-body><![CDATA[%variable:totalPass>size% + %variable:totalFail>size%]]></ac:plain-text-body>
</ac:structured-macro>
<p>
<br/>
</p>
<p>
<br/>
</p>
<p>
<br/>
</p>
<pre class="syntaxhighlighter-pre"> <br/>
</pre>
<p>
<br/>
</p>
<p>
<br/>
</p>
Macro structure
You can recreate the example in the editor view:
N/A
Steps
Create a Table Data macro and set the Name to "failpass".
Within the Table Data macro, create a table and insert a List Data macro.
Set the Name to "result".Inside the List Data macro insert two List Option macros.
Set the values of List Option macros to "fail" and "pass".Create a Report Variable macro.
Set the name to "totalFail".Within the Report Variable macro create a Local Reporter macro.
Set the Key to "data:failpass
".Inside the Local Reporter macro, create a Text Filter macro.
Set the Key to "data:result
" and Exact Value to "fail".Create another Report Variable macro.
Set the Name to "totalPass".Within the Report Variable macro create a Local Reporter macro.
Set the Key to "data:failpass
".Inside the Local Reporter macro, create a Text Filter macro.
Set the Key to "data:result
" and Exact Value to "pass".Create a Report Info macro.
Set Key to "variable:totalFail>size
".Create a Report Info macro.
Set Key to "variable:totalPass>size
".Finally, create a Report Eval macro, and enter the following inside:
%variable:totalPass>size% + %variable:totalFail>size%