I have one excel file, more than 200 lines, structure below:

column A B C D E F G
company department revenue company department revenue difference
0092 R010 1000 0190 R090 100
0190 R020 1100 0092 R001 300
0190 R030 2000 0092 R010 200

we have so many rows, we need to calculate column G, which is C-F but for same company and department, how to do?

in this case, row 1, column G should be 1000-200 (in row 3,column F)=800, for company 0092 and R010 (based on column A and B)

any idea to be fast