I know that there is no way of using MATCH, UNWIND or FILTER within a FOREACH loop, but do not what could solve the problem. I have the following query to start,

`MATCH (u:User)-[s:SIMILAR]-(:User)-[t:TRIED]-(p:Product)`

The TRIED has 10 properties with values 0-3 but the SIMILAR relationship has a property of s.strength which can be any integer value greater than 5

What I am trying to create is an average of averages using the following

`sum((strength * (average of t1 at strength = 6) + (strength * (average of t1 at strength = 7) ..... )`

example:

strength = 7

t1 = 1, 1, 1, 0

result = 5.75

the following grid is the desired average results from the first part of the equation

```
s.strength | strSum
| 7 | 8 | 9 |
t.t1 | 5.25 | 0 | 0 | 5.25
t.t2 | 19.25 | 16 | 27 | 62.25
t.t3 | 21 | 24 | 27 | 72
```

I then want to take the strSum value and divide it

`sum((strength * (average of t1 at strength = 6) + (strength * (average of t1 at strength = 7) ..... ) / sum(distinct s.strength)`

to give me an average of averages weighted by s.strength.

Does anyone have a way to iterate through all the values of s.strength and return these weighted averages or is there an APOC proceedure that would help with this. I have been looking at the periodic.rock_n_roll_while bit am not quite sure if this is right.

Below is some test data to create and setup the graph that would give the above grid results

```
CREATE (u:User {ID: 'A'}), (p:Product {ID: 'A'}) WITH u, p
MERGE (u)-[:SIMILAR {strength: 7}]-(:User {ID: 'B'})-[t:TASTED {t1: 1, t2: 3, t3: 3}]-(p) WITH u, p
MERGE (u)-[:SIMILAR {strength: 7}]-(:User {ID: 'C'})-[t:TASTED {t1: 1, t2: 3, t3: 3}]-(p) WITH u, p
MERGE (u)-[:SIMILAR {strength: 7}]-(:User {ID: 'D'})-[t:TASTED {t1: 1, t2: 3, t3: 3}]-(p) WITH u, p
MERGE (u)-[:SIMILAR {strength: 7}]-(:User {ID: 'E'})-[t:TASTED {t1: 0, t2: 2, t3: 3}]-(p) WITH u, p
MERGE (u)-[:SIMILAR {strength: 8}]-(:User {ID: 'F'})-[t:TASTED {t1: 1, t2: 2, t3: 3}]-(p) WITH u, p
MERGE (u)-[:SIMILAR {strength: 8}]-(:User {ID: 'G'})-[t:TASTED {t1: 1, t2: 2, t3: 3}]-(p) WITH u, p
MERGE (u)-[:SIMILAR {strength: 9}]-(:User {ID: 'H'})-[t:TASTED {t1: 0, t2: 3, t3: 3}]-(p)
```

EDIT: fix incorrect values in t1