# Filter by value when reading and calculating data using pgfplotstable

I am trying to plot data from a file, using pgfplots for the plot and pgfplotstable to read in the data and calculate a new column (cummulative values from another row), which is plotted as well. My data sometimes has bad values (negative values when all values should be non-negative) and I would like to filter those values from the plot and the calculation, either by ignoring them or setting them to zero. pgfplots has a convenient filter option for the plots, but this has no effect on the calculated column.

Here's a MWE of what I am trying to accomplish. There should not be any negative values in the plots. How should I filter the values?

\documentclass{minimal}

\usepackage{filecontents}
\begin{filecontents}{data.csv}

Time,TemperatureC,DewpointC,PressurehPa,WindDirection,WindDirectionDegrees,WindSpeedKMH,WindSpeedGustKMH,Humidity,HourlyPrecipMM,Conditions,Clouds,dailyrainMM,SoftwareType,DateUTC,
\end{filecontents}

% UNITS
\usepackage{siunitx}

% PGFPLOTS and TABLES
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{
width=10cm,
compat=1.7}
\usepgfplotslibrary{dateplot}
\usepgfplotslibrary{groupplots}

\usepackage{pgfplotstable}
\pgfplotstableset{
col sep=comma,
create on use/SumP/.style={
create col/expr={\pgfmathaccuma + \thisrow{HourlyPrecipMM}}
}
}
% ------------------------------------------------- Document starts here
\begin{document}

\begin{tikzpicture}
\begin{groupplot}[
group style={%
group size=1 by 2,
horizontal sep=0pt,
vertical sep=10pt,
xticklabels at=edge bottom,
xlabels at=edge bottom,
ylabels at=edge left,
},
legend style={draw=none},
legend pos=north west,
legend cell align=left,
date coordinates in=x,
xtick=,
xticklabel style={rotate=90,anchor=near xticklabel},
xticklabel=\month-\day. \hour:\minute,
date ZERO=2012-10-23,
minor tick num=12,
footnotesize,
width=10cm,
xlabel=Time / \si{\hour},
ylabel=P / \si{\mm},
ybar
]
\nextgroupplot[]
{\data};
\addplot+[const plot mark left, fill=none,dashed] table[x=Time,y=SumP]
{\data};
\nextgroupplot[ymax=100,height=4cm]
{\data};

\end{groupplot}
\end{tikzpicture}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-engine: xetex
%%% TeX-master: t
%%% End:

-

For accumulating only the non-negative values, you can use the expression \pgfmathaccuma + max(\thisrow{HourlyPrecipMM},0), where max(\thisrow{HourlyPrecipMM},0) evaluates to the data value if it's non-negative, and 0 if it's negative.
For filtering negative coordinates from the plots, you can set the key restrict y to domain=0: (leaving the upper bound empty).