If you unpivot, then pivot again the result can be achieved:
with cte as (
/* this is the equivalent of an "unpivot" but using cross apply instead */
select
ca.*
from #temptable
cross apply (
values
(TimePeriod, 'Transactions', Transactions)
, (TimePeriod, 'SalesAmount', SalesAmount)
, (TimePeriod, 'NoEmployees', NoEmployees)
, (TimePeriod, 'Items', Items)
, (TimePeriod, 'Returns', Returns)
) ca (hdg, metric, val)
)
SELECT metric, [ThisMonth],[LastMonth], [ThisYear], [LastYear]
FROM cte
pivot (
max([val])
FOR [hdg] IN ([ThisMonth],[LastMonth], [ThisYear], [LastYear])
) p
;
result:
metric ThisMonth LastMonth ThisYear LastYear
---- -------------- ------------ ----------- ------------ ------------
1 Items 1000,00 1020,00 14890,00 16123,00
2 NoEmployees 230,00 232,00 321,00 311,00
3 Returns 200,00 109,00 564,00 342,00
4 SalesAmount 2343423,41 433245,50 1391468,43 1699713,64
5 Transactions 5000,00 6000,00 50000,00 60000,00
see: https://rextester.com/EIXT79068
OR, by using brute force:
SELECT
'Items' as Metric
, max(case when TimePeriod = 'ThisMonth' then Items end) ThisMonth
, max(case when TimePeriod = 'LastMonth' then Items end) LastMonth
, max(case when TimePeriod = 'ThisYear' then Items end) ThisYear
, max(case when TimePeriod = 'LastYear' then Items end) LastYear
FROM #temptable
union all
SELECT
'NoEmployees' as Metric
, max(case when TimePeriod = 'ThisMonth' then NoEmployees end) ThisMonth
, max(case when TimePeriod = 'LastMonth' then NoEmployees end) LastMonth
, max(case when TimePeriod = 'ThisYear' then NoEmployees end) ThisYear
, max(case when TimePeriod = 'LastYear' then NoEmployees end) LastYear
FROM #temptable
union all
SELECT
'Returns' as Metric
, max(case when TimePeriod = 'ThisMonth' then Returns end) ThisMonth
, max(case when TimePeriod = 'LastMonth' then Returns end) LastMonth
, max(case when TimePeriod = 'ThisYear' then Returns end) ThisYear
, max(case when TimePeriod = 'LastYear' then Returns end) LastYear
FROM #temptable
union all
SELECT
'SalesAmount' as Metric
, max(case when TimePeriod = 'ThisMonth' then SalesAmount end) ThisMonth
, max(case when TimePeriod = 'LastMonth' then SalesAmount end) LastMonth
, max(case when TimePeriod = 'ThisYear' then SalesAmount end) ThisYear
, max(case when TimePeriod = 'LastYear' then SalesAmount end) LastYear
FROM #temptable
union all
SELECT
'Transactions' as Metric
, max(case when TimePeriod = 'ThisMonth' then transactions end) ThisMonth
, max(case when TimePeriod = 'LastMonth' then transactions end) LastMonth
, max(case when TimePeriod = 'ThisYear' then transactions end) ThisYear
, max(case when TimePeriod = 'LastYear' then transactions end) LastYear
FROM #temptable
;
My guess is that in altering the query you are using to get to #temptable could make this a whole lot easier