Hi @Andrei_Croitoru ,
As per the Input Image provided, and based on the Groupings done on the First Columns, we can assume that you want to Group the same values and get it’s Number of Occurrences.
But the Groupings on the last column are still not clear. If you could explain How/Why the Last Column Values should be grouped in that manner, it would able us to get the logic and provide a Solution faster.
Also if you Could provide us with a Sample Excel file with the Above Input, it would be helpful to Test Solution Developed.