This forum isn't for solving your programming tasks. But for the fun of it:
select Year, Account, 'Measure1' as Measure, Measure1 as A, null as B, null as C
from my_table
where Location = 'A'
union
select Year, Account, 'Measure2' as Measure, Measure2 as A, null as B, null as C
from my_table
where Location = 'A'
...
union
select Year, Account, 'Measure1' as Measure, null as A, Measure1 as B, null as C
from my_table
where Location = 'B'
...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…