How to get a 'vote' count from the data in a table cell
Asked by Brad Johnson:

I want to setup a product roadmap section where individual pages can be created, one per suggested change, and users can vote for a feature and a report lists the features sorted in descending order of votes so it shows from most popular to least popular.

I tried using Page Properties and Page Properties Report, including the 'Likes' metadata and the Likes appear great in the Page Properties Report but I can't sort on Likes. This would have been great as it doesn't involves Users editing a page in order to vote. The downside is without analytics we couldn't see who voted (which might be important).

I can add a Votes (Name) and Votes (Count) to the table on each page and tell users they have to add their name and increment the Count and then sort the report by Votes (Count) but that's a bit bleh.

I could just have the Votes (Name) in each table and maybe use Table Transformer to count the names (using SQL and/or regex) and add a new column as part of the report but that's beyond my capabilities. I would prefer the name to be a [@mention](/t5/user/viewprofilepage/user-id/732788) but also OK if they have to type it in as text if there is a solution here.

I would love to hear any ideas on how to achieve this expanding either on my ideas above or any new idea.


Answers:
author: Katerina Kovriga {Stiltsoft}
body: Hi [@Brad Johnson](/t5/user/viewprofilepage/user-id/4838726) ,

If you need help with the [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 (or maybe the [Pivot Table](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Pivot+Table+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro will suit you), you may give us a manually created table with dummy data that looks like the Page Properties Report macro that you will get for the real use case. Then you may provide us with the desired output (to count distinct names, votes, etc.) and how you want it to look like (again with the help of a manually created table).

We can work here or via [our support portal](https://jsd.stiltsoft.com/servicedesk/customer/portal/2) that is confidential (we can use real screenshots there).

But again if we are talking about usernames, features and voting, maybe it is not very convenient to use manual work? Type in names, increment the numbers, etc.

Maybe it's easier to use apps for voting - we also provide one for Confluence Cloud and **it's free** . Please check the [Pollmaker for Confluence](https://marketplace.atlassian.com/apps/1224994/poll-maker-for-confluence?hosting=cloud&tab=overview).

With its help you'll be able to create single and multi vote questions and decide what kind of polls you need: anonymous or "clear" where you will see the voters' avatars.

comments: author: Brad Johnson
body: Hi Katerina,

i had looked at Pollmaker but I really want to setup a template for users to create pages and capture the description and requires menus for the feature and have people vote directly on that page rather than manually re-enter feature titles into poll maker.   

I'll post some detail of what I'd like tomorrow.


author: Katerina Kovriga {Stiltsoft}
body: If you have the examples of real source tables with data for the Page Properties Report macro (with headers that we'll be able to use inside the SQL query), raise a [support ticket](https://jsd.stiltsoft.com/servicedesk/customer/portal/2) - attach the screenshots for our agents to recreate similar tables and guide you through the process.

If you prefer manually created tables with dummy data, you may update this thread.


author: Brad Johnson
body: Here is an example of a table on the feature page

I have typed names as text here for privacy while posting this. I would prefer people @ mention themselves but would accept either really as I don't expect people to misspell their own name..

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/192865iD068E56EFAA9B327/image-dimensions/325x113?v=v2 "image.png")

Here is what the report could look like. Its simply a page properties report of the features sorted by most popular (The row order should be reversed in the below). A solution could be that the report view would show a column of the count of the names in the 'Vote (Names) field and it would be sorted by that. If we can't count @mentions then we might need to enforce a format, like a separator (e.g. comma) or tell people to always put first and last name so we know 2 words is one vote.

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


author: Katerina Kovriga {Stiltsoft}
body: And there will be no the "Votes (Count)" column in the result table? This column was shown in the original one-row table.

If no and you want to count names in the cells, what element is supposed to be between them? The space?

As I see the case, it will be much easier to use the Table Excerpt/Table Excerpt Include macros. You can also collect tables via these macros and show the source page link. But you'll be able to collect multiple-row tables - your users can each have their own row. So, every username will be placed into a separate cell - it's much easier to count them. The simple Pivot Table macro will do.

What concerns the several mentions in one cell, I'll take a look: again please tell how they are separated (if we won't be able to use the @ in the query to count/separate them).


author: Brad Johnson
body: Sorry for the confusion. I should have removed the Votes (Count) column in the first table because I want to calculate the count based off the number of names entered in Votes (Name).

This feature is new. I will implement whatever is deemed feasible. I would prefer to count @mentions, otherwise I can specify how users need to enter their name. Likely FirstName LastName and a comma separator.

I would rather not let users have their own row. I'll end up with tables that have a hundred rows of users.

I will use anything that's feasible to separate @mentions as well. Anything you can make work.

Thanks for your help. I'm really excited to introduce this feature and I can't wait to see what you come up with.


author: Katerina Kovriga {Stiltsoft}
body: Thank you, I'll return here shortly.


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

So here is a possible solution for the case:

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

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

**SELECT \*,**   
**LENGTH('Votes (Name)') - LENGTH(REPLACE('Votes (Name)', "!", "")) AS 'Votes (Count)'**   
**FROM (SELECT \*, CASE WHEN 'Votes (Name)' IS NULL**   
**THEN "No votes"**   
**ELSE 'Votes (Name)'**   
**END**   
**AS 'Votes (Name)' FROM T1)**

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

I'm gonna try to describe what I have done here and why.)))

The second part of the query that is

**(SELECT \*, CASE WHEN 'Votes (Name)' IS NULL**   
**THEN "No votes"**   
**ELSE 'Votes (Name)'**   
**END**   
**AS 'Votes (Name)' FROM T1)**

is required to work with empty cells (when your features don't have any votes). Later we need them to become strings, so we check if they are empty (IS NULL) and paste the "No votes" expression inside each empty cell.

The first part of the query that is

**SELECT \*,**   
**LENGTH('Votes (Name)') - LENGTH(REPLACE('Votes (Name)', "!", "")) AS 'Votes (Count)'**   
**FROM**

is required to count the number of user names (@mentions).

Here comes the difficulty: the "@" character is a virtual one for such @mentions, it can't be seen by macros and counted using SQL.

So we need some real characters to split user mentions. Maybe it looks better with spaces, but they are very likely to be missed and besides it will be confusing for the macro while operating with empty cells.

So I took an exclamation mark and placed it before every user mention: you can relate to it as a vote confirmation (at first we confirm it, then insert our name).

Or you may use "+" instead - change the source table and this part of the query **LENGTH(REPLACE('Votes (Name)', "+", "").**

Now we can count the number of exclamation marks in the cell that equals to the number of our votes.

Hope this helps.


author: Brad Johnson
body: Perfect!

I switched to ',' for the separator as I think it will make more sense to users. I'll leave an instruction that there must always be a comma at the end. If they forget then it'll just be missing one vote.   

Thanks for this.

FYI I tell everyone who will listen that confluence is great but Stiltsoft makes it awesome. Your product, your documentation, and especially your support are 10 / 10.


author: Katerina Kovriga {Stiltsoft}
body: The "," may be confusing if there is only one vote or your vote is the last:

\| @katerinakovriga, \|

\| @katerinakovriga, @johhnsmith, \|

Commas indeed are mostly used like separators, but here it's better to use something that equals the number of user names. From our experience, variants like "plus one ..."

\| + @katerinakovriga , + @johhnsmith, \|

are better - people tend to forget commas and points, especially if they go to the end of the line.

P.S. It's just our personal experience, I hope that if somebody really wants this or that feature, they will follow the instruction and make sure that their vote is not missing. )))))

Thank you for the positive feedback! I'm going to show your message to the whole Table Filter and Charts team!


author: Brad Johnson
body: Thought it was worth double checking, there is no ways to count mentions? They aren't single words that could be counted?

Or if we can assume very name in a mention is two words count pairs of words?


author: Katerina Kovriga {Stiltsoft}
body: It's a string of words - you are right. And the words are counted by separators (spaces, commas, etc.).

I mean even not considering SQL, but in general (for Python, for example) if you have a sentence and need to count its words, you will look for the spaces. Otherwise you don't know where the new word begins and ends as the length is different.

So, I don't see any workaround as for now.

The easiest way is to put each name in a separate cell as I've mentioned before.


Tags: cloud

confluence-cloud