Hi,
pasbal wrote:
- How can i reuse \DTLrowcount{dbTest} with an mathematical operation ?
Expected result : Rows = 5
Isn't that what
\DTLrowcount{dbTest}
yields in this case?
Or are you after something like
\edef\numberofrows{\DTLrowcount{dbTest}}
, i.e., to be able to use
\numberofrows
as a variable?
pasbal wrote:
- I would like to count each key equal to A then B ... in the column A and use it for a calcul. I found this code
Code: Select all
\def\Somme{0}
\DTLforeach[\DTLiseq{\ColA}{A}]{dbTest}{\ColA=ColA}{\DTLadd{\Somme}{1}{\Somme}}
\Somme
but is there a similar command like \DTLsumcolumn{dbTest}{ColB}{\Total}\Total ?
Expected result
A=2 => 2/5
B=2 => 2/5
D=1 => 1/5
- I would like to add each value in the column B when the key is equal A then B ... and use it for a calcul.
Expected result
A 2.25/6.75 =
B 2/6.75
D 2.5/6.75
Well, instead of using
\DTLforeach
to create just the number of rows, you could use it to create the sum of relevant points.
The number of effective rows (since you're using a condition) can be obtained by calling
\DTLsavelastrowcount
.
pasbal wrote:
- I would like to list each string in the column C when the key is equal A then B ... and use it with \cref
Expected result
List A => \cref{A,DSa}
List B => \cref{Ba,RE}
uhhmm, do you really have a label called `A' in your TeX file (and another one called `DSa')? Or do you have a label called `A,DSa'? The latter does not work with cleveref's
\cref
command that way: the comma is used here as separator between labels.
Code: Select all
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage{datatool}
\usepackage[french]{cleveref}
\usepackage{filecontents}
% datatool loads fp package already
\usepackage{siunitx}
\begin{document}
%création base
\begin{filecontents}{dbTest.csv}
ColA,ColB,ColC
A,1,A
B,1.5,Ba
A,1.25,DSa
D,2.5,Aza
B,0.5,RE
\end{filecontents}
\DTLloaddb{dbTest}{dbTest.csv}
\DTLdisplaydb{dbTest}
\edef\numberofrows{\DTLrowcount{dbTest}}%
\DTLsumcolumn{dbTest}{ColB}{\Total}
Total points : \Total
\def\SumB{0}
\DTLforeach[\DTLiseq{\ColA}{A}]{dbTest}{\ColA=ColA, \ColB=ColB}{\DTLadd{\SumB}{\SumB}{\ColB}}
\DTLsavelastrowcount{\Somme}%
NB colonne A :\Somme
Number of rows: \numberofrows
\DTLdiv{\relrows}{\Somme}{\numberofrows}%
\DTLmul{\relrows}{\relrows}{100}%
\DTLround{\relrows}{\relrows}{1}%
`A' rows: \SI{\relrows}{\percent} (\Somme/\numberofrows)
\DTLdiv{\SBa}{\SumB}{\Total}%
\DTLmul{\SBap}{\SBa}{100}%
\DTLround{\SBa}{\SBa}{2}%
\DTLround{\SBap}{\SBap}{1}%
\DTLround{\SumB}{\SumB}{2}%
\DTLround{\TotalR}{\Total}{2}%
`A' rows contain \SumB\ points of total \TotalR\ points or \SBa, read \SI{\SBap}{\percent}
\end{document}
KR
Rainer