Table column names in KDB must be characters, not any other data types.
In the pivot table, the data type of the year column is int \ long, so the reason is that the correct table does not open.
If you type it as a symbol, then it will work.
q)growth:([] stock:asc 9#`goog`apple`nokia; year: 9#2015 2016 2017; returns:9?20 ) q)growth:update `$string year from growth q)exec (distinct growth`year)#year!returns by stock:stock from growth stock| 2015 2016 2017 -----| -------------- apple| 9 18 17 goog | 8 13 17 nokia| 12 12 2
Alternatively, you can switch the columns of the pivot table to "stock" rather than "year" and get a pivot table with the same source table.
q)growth:([] stock:asc 9#`goog`apple`nokia; year: 9#2015 2016 2017; returns:9?20 ) q)show exec (distinct growth`stock)#stock!returns by year:year from growth year| apple goog nokia ----| ---------------- 2015| 4 2 4 2016| 5 13 12 2017| 12 6 1
source share