While @MayukhBhattacharya provided the sophisticated formula which perfectly works, the simple pivot table goodly gives the desired result:
I guess no explanation is required.