Excel中A3:F6是带表头的典型表格,但上面多了额外的两行表头:
|---|---------|---------|-------------|-------------|----------|----------|
| | A | B | C | D | E | F |
| 1 | | | Actuals | Actuals | Plan | Plan |
| 2 | | | FY20 | FY21 | FY20 | FY21 |
| 3 | Country | Owner | 1/1/2020 | 1/1/2020 | 1/1/2020 | 1/1/2020 |
| 4 | France | Richard | 100 | 150 | 80 | 160 |
| 5 | France | Martin | 120 | 140 | 130 | 140 |
| 6 | France | Pierre | 50 | 100 | 50 | 80 |
现在要将典型表格连同额外的两行表头同时进行列转行:
|----|-------------|-----------|-------------|----------|----------|-----------|
| | A | B | C | D | E | F |
| 9 | Country | Owner | Version | Year | Date | Value |
| 10 | France | Richard | Actuals | FY20 | 1/1/2020 | 100 |
| 11 | France | Richard | Actuals | FY21 | 1/1/2020 | 150 |
| 12 | France | Richard | Plan | FY20 | 1/1/2020 | 80 |
| 13 | France | Richard | Plan | FY21 | 1/1/2020 | 160 |
| 14 | France | Martin | Actuals | FY20 | 1/1/2020 | 120 |
| 15 | France | Martin | Actuals | FY21 | 1/1/2020 | 140 |
| 16 | France | Martin | Plan | FY20 | 1/1/2020 | 130 |
| 17 | France | Martin | Plan | FY21 | 1/1/2020 | 140 |
| 18 | France | Pierre | Actuals | FY20 | 1/1/2020 | 50 |
| 19 | France | Pierre | Actuals | FY21 | 1/1/2020 | 100 |
| 20 | France | Pierre | Plan | FY20 | 1/1/2020 | 50 |
| 21 | France | Pierre | Plan | FY21 | 1/1/2020 | 80 |
使用 SPL XLL,输入公式:
=spl("=c=transpose(?2),?1.conj( (a=~).m(3:).(a.to(2)|c(#)|~))",A4:F6,C1:F3)
=spl("=c=transpose(?2),?1.conj( (a=~).m(3:).(a.to(2)|c(#)|~))",A4:F6,C1:F3)
transpose将表头 C1:F3 进行转置,conj 合并集合成员,~ 表示表格 A4:F6 每一行,m(3:) 表示从每行的第 3 个成员取到结尾。