I've searched web and forums to some extent and have seen several different ways of calculating a median average, but only for simple columns that aren't grouped. I have data that is similar to this and need to extract a median value for each "bank." Any help would be greatly appreciated!

select bank, AVG(data) as Medianfrom ( select bank,data, ROW_NUMBER() over (partition by bank order by data ASC) as DataRank, COUNT(*) over (partition by bank) as BankCount from @Temp) xwhere x.DataRank in (x.BankCount/2+1, (x.BankCount+1)/2) group by x.bank