Sum() of string values

I'm new in neo4j and i have a question that i've already tried to solve but nothing.
So, i'm doing a graph and at certain point i have to sum values that i have in a json file, but the value of the field is in string. Here's what i have:

I've readed the neo4j documentation and found the toFloat function, but when i try to do it, i always get null values:

When i try to do: sum(toFloat(C.Preco)) i get this:

What i want to do is to sum all the values from the column: "C.Preco". How do i do it?


I think it's not working since in your string there is a "." and a ",".
So you can try to replace the "." and after convert your number to a float.
You can do like this:

toFloat(replace(C.Preco, ".", ""))

Looks like you are using European number system
Try below
return tofloat(replace(replace(C.Preco,".",""),",","."))

Or visit below for APOC code

1 Like

Ok nice, it worked. It has converted to float. But how do i sum those values? Just have to put: return sum(tofloat(replace(replace(C.Preco,".",""),",","."))) ?

Ok, it was like i said: return sum(tofloat(replace(replace(C.Preco,".",""),",",".")))
Thank you very much for your kindness!
Stay safe!

Just for u to understand i have this graph:

I want to sum the value of all Contracts that i have(Contrato in the graph), and that attribute is "C.preco" and IF that sum is > 50.000 i want to, somehow, represent on the graph saying that the center Entitity(506858286) is comitting a fraud. Is that possible? I know that neo4j has not if/else clause

Try below

With e1, sum(tofloat(replace(replace(C.Preco,".",""),",","."))) as sumPreco
Where sumPreco >50000
Return e1 as Entity, sumPreco

  1. As you are using European number system you can transform 50.000 as per need
  2. Neo4j does not have **If Else **, however we have Case Expression
    Expressions - Cypher Manual
1 Like

This is what i get.
I had to change: Match (e1:ENTIDADE) -(c:CONTRATO)->(e2:ENTIDADE) to Match (e1:ENTIDADE) -[C]->(e2:ENTIDADE) because it gives me error if i have (c:contrato) and not [c]

Oh, ok, i tought it would appear the graph and some kind of label in the FraudulentEntities. After i see the tables i've understood that neo4j is returning me only the FraudulentEntities. Thank you friend!
Have a nice day, and stay safe!