Refactored groupedBar transform method