As requested by [Merging multiple different tables records. // Splitting table records in tables](https://tex.stackexchange.com/questions/439517/merging-multiple-different-tables-records-splitting-table-records-in-tables/439615?noredirect=1#comment1105851_439615).

I there is a command that I created (a varaint I found here).

```
\newcounter{magicrownumbers}
\newcommand\contactnumber{Nr: \stepcounter{magicrownumbers}\arabic{magicrownumbers}}

```

Where it is just a simple counter.
When used it just add +1 to the last value.
It is used below.

Now the Issue I have is that the filecontents part. When read multiple times, this command is re-invoked. I want to get the filecontents part to maintain the results of the commands at creation time. To not be able to change every time I use values of the part.

When first running the example you will see the issue more clearly then I an able to explain. 

```
\documentclass[a4paper, 10pt]{article} % for A4 size paper
\usepackage{array,etoolbox}
\usepackage{datetime2}
\usepackage{array}
\usepackage{booktabs}
\usepackage{pgfplotstable} 
\usepackage{etoolbox}
\usepackage[yyyymmdd]{datetime}
\usepackage{filecontents}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[T1]{fontenc}
\usepackage{xmpincl}

\pgfplotsset{compat=1.15}
\pgfplotstableset{
    string type,
    column type=l,
    every head row/.style={
        before row=\toprule,
        after row=\midrule,
    },
    every last row/.style={
        after row=\bottomrule
    },  
}

\begin{document}
\newcounter{magicrownumbers}
\newcommand\contactnumber{Nr: \stepcounter{magicrownumbers}\arabic{magicrownumbers}}

\begin{filecontents}{mytable.dat}
    Moment  Date  Type  subject
    {\contactnumber}     {\today}      RED      Pie
    {\contactnumber}     {\today}      BLUE     Pie         
    {\contactnumber}     {\today}      RED      Apple
    {\contactnumber}     {\today}      BLUE     Apple
\end{filecontents}

\pgfplotstableread{mytable.dat}{\mytable}

Whole table:\bigskip

\pgfplotstabletypeset{\mytable}

\bigskip\bigskip Table with only rows with column ``Type''=BLUE:\bigskip

\pgfplotstabletypeset[
    row predicate/.code={%
        \pgfplotstablegetelem{#1}{Type}\of\mytable%
        \ifdefstring{\pgfplotsretval}{BLUE}{}{\pgfplotstableuserowfalse}%
    },
    ]{\mytable}

\bigskip\bigskip Table with only rows with column ``Type''=RED:\bigskip

\pgfplotstabletypeset[
    row predicate/.code={%
        \pgfplotstablegetelem{#1}{Type}\of\mytable%
        \ifdefstring{\pgfplotsretval}{RED}{}{\pgfplotstableuserowfalse}%
    },
    ]{\mytable}

\end{document}

```