I have a problem with the summation of max values in a column. As you see below, my table has different master spendings and their subbranches. I want to sum the master spendings, in that case only YA.XXXX codes. I've tried some set analysis solutions but they didn't work. When I tried to use aggr() function, I got some results which were not correct. I could use max function for every one of master spendings but my table has so many rows , so that was impossible. If you help me, I would be glad.