-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpivot-data.sql
29 lines (22 loc) · 952 Bytes
/
pivot-data.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- =========================================================================
-- Description:
-- 1. This query show you how to pivot data using the "use Tools.Pivot" tool
-- =========================================================================
-- Load a file of model allocations from Drive
-- The data is structured as one row per portfolio-sector-location allocation
@model_portfolios_orginal = use Drive.csv
--file=/luminesce-examples/model_portfolios.csv
enduse;
-- Transform the data
@model_portfolios_formatted =
select model_port_name as [ModelPortfolioCode],
weighting as [AllocationPercentage],
(sect || "_" || loc) as [AllocationTarget]
from @model_portfolios_orginal;
-- Pivot the data so the model portfolio codes are returned as columns
@model_portfolios_pivoted =
use Tools.Pivot with @model_portfolios_formatted
--key=ModelPortfolioCode
--aggregateColumns=AllocationPercentage
enduse;
select * from @model_portfolios_pivoted;