How to calculate percentage breakdown of a relationship property in Cypher and NeoDash

I am looking to create a bar chart in NeoDash using Cypher which gives the percentage of each response (r.Response), (Categories are - Accepted, Declined etc.), a property of the [r:RE_INVITED_TO] relationship, broken down by Gender (p.Gender). Here is my current code -

MATCH (p:REPerson)-[r:RE_INVITED_TO]-(:REEvent)
WITH SUM(toInteger(r.Response)) As total
MATCH (p:REPerson)-[r:RE_INVITED_TO]-(:REEvent)
RETURN p.Gender, count(p),  100.0 * SUM(r.Response) / total

Currently it gives me the error message

sum() can only handle numerical values, duration, and null. Got String("Accepted")

How would I fix this?

I think all your values of r.response can not be converted to an integer. I think at least one value is ‘Accepted’

Hi @Kpanton ,
You probably want to use 'response' as a grouping key here and aggregate by count:

RETURN p.Gender as Gender, r.Response, 100.0 * COUNT(r.Response) / total as Percentage

That should give you a result like this - which you can put in a stacked bar chart:

Gender

Response

Percentage

F

Accepted

60%

F

Declined

40%

M

Accepted

30%

M

Declined

70%