Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-15-2022 12:04 PM
without success I tried to convert a list to a constant (please see attached)
I created the correct calculation
Solved! Go to Solution.
11-15-2022 04:54 PM
I am not sure what you are looking for, but here is an example of calculating the driver total by department and then dividing each by the total across all departments.
match (n:Account{Account:'Acct 6100'})-[r:Driver]->(d:Department)
with n, d.Department as dept, sum(r.Driver) as deptDriverTotal
with n, collect({dept: dept, total: deptDriverTotal}) as deptStats, sum(deptDriverTotal) as total
unwind deptStats as deptStat
return n.amount as amt, deptStat.dept as department, deptStat.total as deptTotal, 100 * (toFloat(deptStat.total) / toFloat(total)) as deptPercentage
What are you trying to accomplish with your last query? In summary, it looks like you have calculated the total of all the Drivers and then updated the driver relationship with the ratio of the driver's Driver value and the total. As a note, there is no need for the merges. There is an alternative approach.
11-15-2022 12:57 PM
As a note, you can calculate the sum directly with ‘sum(r.Driver)’ instead of apoc.coll.sum(collect(r.Driver)).
what is it you want to calculate? Do you want the total, or the total by driver, and/or ratio of driver total divided by total for each driver?
11-15-2022 01:29 PM
Thank you for taking the time , I would like to create a division of each driver by the total
11-15-2022 02:49 PM
I successfully generated the allocation with the query below.
is there a simple way to achieve the same results without collect and index
11-15-2022 04:54 PM
I am not sure what you are looking for, but here is an example of calculating the driver total by department and then dividing each by the total across all departments.
match (n:Account{Account:'Acct 6100'})-[r:Driver]->(d:Department)
with n, d.Department as dept, sum(r.Driver) as deptDriverTotal
with n, collect({dept: dept, total: deptDriverTotal}) as deptStats, sum(deptDriverTotal) as total
unwind deptStats as deptStat
return n.amount as amt, deptStat.dept as department, deptStat.total as deptTotal, 100 * (toFloat(deptStat.total) / toFloat(total)) as deptPercentage
What are you trying to accomplish with your last query? In summary, it looks like you have calculated the total of all the Drivers and then updated the driver relationship with the ratio of the driver's Driver value and the total. As a note, there is no need for the merges. There is an alternative approach.
11-16-2022 02:26 PM
Thank you!
All the sessions of the conference are now available online