Hi,
I want to allow the user to dynamically choose the columns to pivot by in Pulse?
Is this possible?
Thanks.
q)
Hi Quantific,
Let’s assume you have the kdb+ pivot code (https://stackoverflow.com/questions/30789471/pivot-table-in-kdb-q) and that:
trades_agg:1000#0!trades_agg
Then providing a UI to select columns is simple.
Example video: https://youtu.be/GyTQqKmymSU
Steps:
- Add table trades_agg
- Add a Multi-select component with sql query: ([] c:cols trades_agg)
- Add a Multi-select component with sql query: ([] c:cols trades_agg)
- Add a Dropdown select component with sql query: ([] c:cols trades_agg)
- Add another table with the query:
piv[trades_agg;(),<code>${{key1}}; (),
${{key2}}; (),`${{key3}}]
i.e. You want three variables, then to place those 3 variables into the piv function while making sure they are lists of symbols.
// see https://stackoverflow.com/questions/30789471/pivot-table-in-kdb-q
// I then aggregate the data into equal sized buckets
piv:{[t;k;p;v]
/ controls new columns names
f:{[v;P]`${raze ” ” sv x} each string raze P[;0],’/:v,/:\:P[;1]};
v:(),v; k:(),k; p:(),p; / make sure args are lists
G:group flip k!(t:.Q.v t)k;
F:group flip p!t p;
key[G]!flip(C:f[v]P:flip value flip key F)!raze
{[i;j;k;x;y]
a:count[x]#x 0N;
a[y]:x y;
b:count[x]#0b;
b[y]:1b;
c:a i;
c[k]:first'[a[j]@’where'[b j]];
c}[I[;0];I J;J:where 1<>count'[I:value G]]/:\:[t v;value F]};
/piv[trades_agg;date
symtime;
exchangebuysell;
shares]