Hello,
To sort by the custom location, you'll have to add the custom location field to the sql code then update the order by clause to with the field's position number or field name (depending on your version of SQL Server).
In the example below, I made up a custom location field called "Location" which is the 7th field in the select statement. I updated the order by clause to order by this field position before ordering by type. You can run the below query and let me know if you have any question.
Remember, you'll have to change my custom location field with your own custom location logic.
Select Top 1000000 DatePart(yyyy, htblticket.date) As Year,
DatePart(mm, htblticket.date) As Month,
'../helpdesk/icons/' + htbltickettypes.icon As icon,
htbltickettypes.typename As Type,
Count(htblticket.ticketid) As TicketCount,
Cast((Count(htblticket.ticketid) / Cast(TicketCount.Amount As decimal) *
100) As decimal(10,2)) As [Type%],
case ROW_NUMBER() over (order by typename) when 1 then 'Braavos' when 2 then 'Mereen' when 3 then 'Qarth'
when 4 then 'Mereen' else 'King''s Landing' end as Location
From htblticket
Inner Join htbltickettypes On htbltickettypes.tickettypeid =
htblticket.tickettypeid
Inner Join (Select DatePart(yyyy, htblticket.date) As Year,
DatePart(mm, htblticket.date) As Month,
Count(htblticket.ticketid) As Amount
From htblticket
Where htblticket.spam <> 'True'
Group By DatePart(yyyy, htblticket.date),
DatePart(mm, htblticket.date)) As TicketCount On TicketCount.Year =
DatePart(yyyy, htblticket.date) And TicketCount.Month = DatePart(mm,
htblticket.date)
Where htblticket.spam <> 'True'
Group By DatePart(yyyy, htblticket.date),
DatePart(mm, htblticket.date),
htbltickettypes.typename,
htbltickettypes.icon,
TicketCount.Amount
Order By Year Desc,
Month Desc,
7, Type