How to do proper variable propagation?

My use case is:
schema:
I have 3 nodes Candidate, Experience,Company
My relationships between these nodes are Candidate <HAS_EXPERIENCE> Experience <WORKED_AT> Company
For a given candidate, he can have mutliple experiences at the same Company.
Let Y be a candidate
I need to find out similar candidates who have worked in the companies Y have worked.I have to sort the resultant candidates based on the similarity.
I wrote a query as below

{
	me as var(func:type(Candidate_PHENA0059))@filter(eq(imProfileId,"7987184")) {
    HAS_EXPERIENCE{
			cn as WORKED_AT{
              sc as math(1)

        ~WORKED_AT{
					~HAS_EXPERIENCE@filter(type(Candidate_PHENA0059) and eq(imStatus,"inactive")){
						fscore as math(sc)
      		}
    		}
    }
    }
  }
    TopRecommendations(func: uid(fscore),orderdesc: val(fscore)) @filter(not uid(me,cn))@cascade { 
  		 userId
      val(fscore) 
      HAS_EXPERIENCE{
				WORKED_AT@filter(uid(cn)){
					 name
        }
      }
  }
      
      
      
    
}
      

my results:

{
        "userId": "user1",
        "val(fscore)": 7,
        "HAS_EXPERIENCE": [
          {
            "WORKED_AT": [
              {
                "name": "ADP LLC"
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "ADP LLC"
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "ADP LLC"
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "ADP LLC"
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "ADP LLC"
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "ADP LLC"
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "ADP LLC"
              }
            ]
          }
        ]
      },
      {
        "userId": "user2",
        "val(fscore)": 6,
        "HAS_EXPERIENCE": [
          {
            "WORKED_AT": [
              {
                "name": "Tech Mahindra Ltd."
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "Tech Mahindra Ltd."
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "Ivy Comptech"
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "Ivy Comptech"
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "Tech Mahindra Ltd."
              }
            ]
          },
          {
            "WORKED_AT": [
              {
                "name": "Tech Mahindra Ltd."
              }
            ]
          }
        ]
      },

if we see the results, user1 got more score compared to user2, but in my case user 2 is having much similairty, he has worked in 2 companies Y has worked…
How to change my query in order to get my result?
How to do grouping by comapany in this case?

Hi @Mounika_Mandadi, can you share via DM the Schema and also a sample of your data(don’t need to be a real world data). I can try to elaborate a sample myself but it will take time and I could make mistakes.

Which similarities?

This score doesn’t seem right. It is just a count, right? not sure what it means in terms of information.

Group by works only between 2 levels. It won’t work in 3 levels of traversing.