What would greatly help, performance-wise, would be to create a new field in the loading script. Something like : " Upper(Trim(ACTION_TYPE)) AS UpTrimActionType "
Then you can replace all your " count(distinct if(Upper(Trim(ACTION_TYPE))='DELIVERED',ISSUE_ID) " by count( distinct {< UpTrimActionType = {'DELIVERED'} >} ISSUE_ID)