Be aware that the concept of a LaTeX-counter differs from the concept of a mathematical function in PGF-math.
Seems with your first snippet the problem is:
\taxcalc's first and second argument must be numbers or calls to defined PGF-math-functions—i.e., things which can be used for calculations with PGF-math-things.
But by \vatTotal as first argument the sequence subcost is passed to \taxcalc. That sequence does neither denote such a number nor denote a call to such a defined PGF-math-function.
PGF-math-things cannot/do not "know" that the sequence subcost denotes the name of a LaTeX-counter whose value is to be obtained.
PGF-math-things "assume" that subcost denotes the name of a PGF-math-function implemented by means of PGF-math-things for doing PGF-math-things and therefore "complains" that the function "subcost" is undefined.
Another question is:
Why \bf twice, opening up two nested local scopes?
Seems one local scope and one \bf is sufficient. :-)
You can modify \vatTotal to make sure that the value of the subcost-LaTeX-counter gets expanded "into" \taxcalc's first argument before \taxcalc gets carried out. This way at the time of carrying out \taxcalc the first argument of \taxcalc will not be a character-sequence denoting the name of a LaTeX-counter but will be a number and thus something that is "understood" by the PGF-math-things.
Does
\newcommand*{\taxcalc}[2]{%
\pgfmathparse{#1/(1.0-#2)-#1}%
\pgfmathprintnumber{\pgfmathresult}%
}
\newcommand{\vatTotal}{%
&&&{\bf BTW 21\%}%
&{\bf\euro\expandafter\taxcalc\expandafter{\number\value{subcost}}{0.21}}%
\\*[1.5ex]%
}
work?
Perhaps \textbf{..} instead of {\bf...}:
\newcommand*{\taxcalc}[2]{%
\pgfmathparse{#1/(1.0-#2)-#1}%
\pgfmathprintnumber{\pgfmathresult}%
}
\newcommand{\vatTotal}{%
&&&\textbf{BTW 21\%}%
&\textbf{\euro\expandafter\taxcalc\expandafter{\number\value{subcost}}{0.21}}%
\\*[1.5ex]%
}
Your second snippet works because here the sequence subcost is wrapped into \arabic{...} by the routine \total while the argument of \arabic must denote the name of a LaTeX-counter.
In other words: Here \total takes into account that subcost denotes the name of a LaTeX-counter by applying \arabic to that phrase for obtaining a number which FP-math-stuff can calculate with.
Summa summarum:
The routine \taxcalc from your first snippet processes two arguments whereof each must denote a number or a call to a defined PGF-math-function which in turn delivers a number.
The name of a LaTeX-counter neither denotes such a number nor denotes the call to a defined PGF-math-function.
Therefore you need steps for obtaining the value/number from the name of the LaTeX-counter.
The routine \total processes one argument which must denote the name of a LaTeX-counter.
\total internally applies \arabic for obtaining a number from that which FP-math-thingies can use for calculating.
By the way:
If PGF-math is in use, then I prefer Schrödinger's cat's approach of not using LaTeX-counters at all for holding values of "variables" but using PGF-math-functions that don't process arguments but always deliver the same number.
(Reason: Each LaTeX-counter internally requires allocation of a count-register while the amount of count-registers is limited in LaTeX. Afaik declaring a new PGF-math-function doesn't require allocating another count-register.)
In case a PGF-math-function does not process arguments and always delivers the same number, the name of that PGF-math-function within the context of PGF-math can be taken for a placeholder for that number/for a variable whose value is that number.
subcost? – Joseph Wright Nov 17 '19 at 16:18pgfyou can do\pgfkeyssetvalue{my/variableA}{10}and then do\pgfkeysgetvalue{my/variableA}to get back the10. – Skillmon Nov 17 '19 at 16:19\arabic{#1}looks like you're using a counter forsubcost, you can get the value of a LaTeX counter by using\value{<countername>}, e.g.,\pgfmathparse{\value{#1}/(1.0-#2)-\value{#1}}could work if the first argument to\taxcalcis always a LaTeX counter. – Skillmon Nov 17 '19 at 16:25sagetexpackage which gives you access to a computer algebra system, SAGE which can handle calculations on the fly (e.g. first page of documentation) or calculate statistics easily. SAGE lets you program with the easy to learn Python language, such as in my answer here. – DJP Nov 17 '19 at 17:14xfp, which gives you the macro\fpevalthat can be used for calculations. To e.g., assign a result of some computation to a macro you could do\usepackage{xfp}\newcommand*\MyVarA{10}\newcommand*\MyVarB{20}\newcommand*\MyVarC{}\edef\MyVarC{\fpeval{\MyVarA/\MyVarB}}– Skillmon Nov 17 '19 at 18:02