Hey Neo peeps!
I'm trying to create a shipment pace output that is cumulative (meaning the values add to the previous sum and the line chart should never go down) I'm attempting to do this by using the reduce() function (List functions - Neo4j Cypher Manual). It doesn't seem to be working as expected for me though.
This is one of my attempts at the Cypher (lines 3 & 5 particularly):
MATCH path =(q:Quantity)<-[hq:HAS_QUANTITY]-(sh:Shipment)-[oo:ON_ORDER]->(s:Sales)-[fc:FOR_CONTRACTED]->(a:Account),(s)-[he:HAS_ENTRY]->(oe:OrderEntry)-[hl:HAS_LINE]->(ol:OrderLine)-[hpo:HAS_PRODUCT_ORIGIN]->(po:ProductOrigin)-[hp:HAS_PRODUCT]->(p:Product)-[hpt:HAS_PRODUCT_TYPE]->(pt:ProductType)
WHERE a.name = $neodash_account_name AND sh.shippedDate.year >= 2019 AND pt.name = $neodash_producttype_name
WITH collect(q.quantity) AS Quantities, sh.shippedDate.year AS Year, sh.shippedDate.month AS Month
ORDER BY Year ASC //reduce(total = 0, x IN Quantities | total + x.quantity)
WITH Month, collect([Year,reduce(total = 0, x IN Quantities | total + x.quantity)]) AS Quantity_Year_Pairs
RETURN Month,
Quantity_Year_Pairs[0][1] AS `2019` ,
Quantity_Year_Pairs[1][1] AS `2020` ,
Quantity_Year_Pairs[2][1] AS `2021`
ORDER BY Month
Here is what I'm going for (note how all the lines only increase in value over time since it is a cumulative sum):
But I get the following error and I can't really find a workaround:
"Type mismatch: expected a map but was Double(1.099750e+02)"
I'd appreciate any advice on the dashboard output or on the reduce() function in general that could help me solve this problem. Thanks in advance, and @niels_dejong 's help would be greatly appreciated!
GQ