Count nodes with a relationship and specific proerties

match (n:Product)-[r:instanceOf]-(m:Category) where exists(n.ID`) and exists(m.ID) return distinct count(n)

This returns the number of relationships in which n and m occurs.

What I want is to find the unique number of n or m where n is instanceOf m and both n & m have the property 'ID'.

Try below

match (n:Product)-[r:instanceOf]-(m:Category) where exists(n.ID) and exists(m.ID) With count(distinct n)  as N, count(distinct m) as M return N, M