# pgfplotstable - Create an additional, calculated, column

how can I get a third column "Z" in the output, where the values are e.g. x*y

\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\usepackage{booktabs}

\begin{filecontents*}{data.dat}
x y
1 2
2 3
3 4
4 5
\end{filecontents*}

\pgfplotstableset{% global config, for example in the preamble
every last row/.style={after row=\bottomrule},
}

\begin{document}
\toprule},
after row=\midrule},
columns/x/.style={column name=x},
columns/y/.style={column name=y},
]{data.dat}
\end{document}


This is how I would like it to look:

Look at para. 4.3.2 of the pgfplotstable manual.

\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\usepackage{booktabs}

\begin{filecontents*}{data.dat}
x y
1 2
2 3
3 4
4 5
\end{filecontents*}

\pgfplotstableset{% global config, for example in the preamble
every last row/.style={after row=\bottomrule},
create on use/z/.style={
create col/expr={\thisrow{x}*\thisrow{y}}}
}

\begin{document}
\pgfplotstabletypeset[

• nice answer (+1)! i wasn't aware for this pgfplotsdtable possibility! apparently, i didn't read manual enough carefully :-( Oct 27, 2017 at 16:25
• @Zarko Thank you! It's the first time I use pgfplotstable, I have just copied the instructions from the manual and adjusted them to fit the OP's case, LOL Oct 27, 2017 at 16:28
• @Zarko, one can do amazing stuff with pgfplotstable, also to its feature for pgfplots (two examples are given in my comment below the question). And there are even more awesome examples here on TeX.SX, but I am to lazy to search for them now. Oct 27, 2017 at 18:02
• @StefanPinnow, thank you for both links. i will analyse your answers and read manual again. so far i rarely use \pgplotstable (because my first impression was "very complicated" ... ; now it seems that i will change my mind :-) ). Oct 27, 2017 at 18:17