‎05-14-2020 02:45 PM
Hi.
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?
Solved! Go to Solution.
‎05-14-2020 04:58 PM
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,".",""),",","."))) ?
‎05-14-2020 04:00 PM
Hello,
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, ".", ""))
‎05-14-2020 04:27 PM
Looks like you are using European number system
Try below
return tofloat(replace(replace(C.Preco,".",""),",","."))
Or visit below for APOC code
https://neo4j.com/docs/labs/apoc/current/mathematical/number-conversions/
‎05-14-2020 04:58 PM
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,".",""),",","."))) ?
‎05-14-2020 05:02 PM
Ok, it was like i said: return sum(tofloat(replace(replace(C.Preco,".",""),",",".")))
Thank you very much for your kindness!
Stay safe!
‎05-14-2020 05:45 PM
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
‎05-14-2020 08:24 PM
Try below
Match (e1:ENTIDADE) -(c:CONTRATO)->(e2:ENTIDADE)
With e1, sum(tofloat(replace(replace(C.Preco,".",""),",","."))) as sumPreco
Where sumPreco >50000
Return e1 as Entity, sumPreco
- As you are using European number system you can transform 50.000 as per need
- Neo4j does not have **If Else **, however we have Case Expression
https://neo4j.com/docs/cypher-manual/current/syntax/expressions/
‎05-15-2020 03:07 AM
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]
‎05-15-2020 03:16 AM
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!