# Calculation node

(Jeffreylm) #1

Hello Everyone,

I have a database where I have products and suppliers. Many suppliers sell the same product, so I want to calculate the ROI for each supplier based on there selling price and attach the output on the SOLD_BY relationship property named ROI.

The goal is for all products to use one calculation node and return there output to the ROI property field.
This already sound like a function has to be used, i'm new to Neo4j. So it would be very helpful if I could do it in one node and have all the different ROI use that node to give a value.

How do I do this?

Greetings,
Jeffrey

0 Likes

(Jennifer Reif) #2

Hello, Jeffrey! What is the other part of the calculation for ROI? I know you mentioned the selling price of each supplier. Is there a unit cost property somewhere for the supplier?

I went ahead and added some pseudo-Cypher....though the exact syntax would depend on where we are getting that other value for the calculation.

MATCH (p:Product)-[r:SOLD_BY]->(s:Supplier)
WHERE r.roi IS NULL
WITH p, r, s
SET r.roi = s.sellingPrice * ???
RETURN count(r)

The return statement should show how many relationships were found in your data set to update. Hope this helps!

Cheers,
Jennifer

0 Likes

(Jeffreylm) #3

Hello Jennifer,

Hope I understand your question properly, so here goes.

So on the SOLD_BY connection there is the price per unit property: SOLD_BY {Price:14:95}
So what you have is each suppliers link to a product has the price on the relationship and on that relationship I would like to also have the ROI calculated and stored next to the Price.

The ROI is calculated using the dimension of the product, it needs to look at at lookup table (price tier based on the weight of the product). So there need to be a way to go through list of weight ranges and choose the correct weight range then the price associated to it.

Example:

100g - 250g \$1,26
251g - 500g \$2,50
501g - 1000g \$3,00

So I most probably will need a node that has all the weight ranges with price tier, so most probably a weight rate node, as each product needs to get the correct price rage value to help calculate the ROI.

Kind regards,
Jeffrey

0 Likes