diff --git a/src/app/components/fixedvar-results/var-results.component.ts b/src/app/components/fixedvar-results/var-results.component.ts
index 14ce066496a0e832582f35c849afcc88016aa41c..a64422e63e6a2424650d18b9eb337edb8ebe7a70 100644
--- a/src/app/components/fixedvar-results/var-results.component.ts
+++ b/src/app/components/fixedvar-results/var-results.component.ts
@@ -8,6 +8,7 @@ import { I18nService } from "../../services/internationalisation.service";
 import { ResultsComponent } from "./results.component";
 import { DialogLogEntriesDetailsComponent } from "../dialog-log-entries-details/dialog-log-entries-details.component";
 import { AppComponent } from "../../app.component";
+import { longestVarParam } from "../../../app/util";
 
 @Component({
     selector: "var-results",
@@ -67,13 +68,8 @@ export class VarResultsComponent extends ResultsComponent {
             // C. pre-extract variable parameters values
             const varValues = [];
             // find longest list
-            this.size = 0;
-            for (let i = 0; i < this._varResults.variatedParameters.length; i++) {
-                const vs = this._varResults.variatedParameters[i].valuesIterator.count();
-                if (vs > this.size) {
-                    this.size = vs;
-                }
-            }
+            const lvp = longestVarParam(this._varResults.variatedParameters);
+            this.size = lvp.size;
             // get extended values lists for each variable parameter
             for (const v of this._varResults.variatedParameters) {
                 const vv = [];
diff --git a/src/app/components/pab-profile-chart/pab-profile-chart.component.ts b/src/app/components/pab-profile-chart/pab-profile-chart.component.ts
index 7651912936e4ece70d94cba60909bfc3342f8154..8005d4ebe8688d8366497c0521ca3a8b26db73e1 100644
--- a/src/app/components/pab-profile-chart/pab-profile-chart.component.ts
+++ b/src/app/components/pab-profile-chart/pab-profile-chart.component.ts
@@ -6,7 +6,7 @@ import { I18nService } from "../../services/internationalisation.service";
 import { ResultsComponent } from "../fixedvar-results/results.component";
 import { PabResults } from "../../results/pab-results";
 import { IYSeries } from "../../results/y-series";
-import { fv } from "../../util";
+import { fv, longestVarParam } from "../../util";
 import { AppComponent } from "../../app.component";
 
 import { CloisonAval, Cloisons, LoiDebit } from "jalhyd";
@@ -132,13 +132,8 @@ export class PabProfileChartComponent extends ResultsComponent {
         if (this._results) {
             this.varValues = [];
             // find longest list
-            this.size = 0;
-            for (let i = 0; i < this._results.variatedParameters.length; i++) {
-                const vs = this._results.variatedParameters[i].valuesIterator.count();
-                if (vs > this.size) {
-                    this.size = vs;
-                }
-            }
+            const lvp = longestVarParam(this._results.variatedParameters);
+            this.size = lvp.size;
             // get extended values lists for each variable parameter
             for (const v of this._results.variatedParameters) {
                 const vv = [];
diff --git a/src/app/components/variable-results-selector/variable-results-selector.component.ts b/src/app/components/variable-results-selector/variable-results-selector.component.ts
index db3456fde3a9594d14e36d7d2a7bb93fb503ba52..fd6e26362e268596a9967cb4576e3ab34014a3f4 100644
--- a/src/app/components/variable-results-selector/variable-results-selector.component.ts
+++ b/src/app/components/variable-results-selector/variable-results-selector.component.ts
@@ -1,7 +1,7 @@
 import { Component, Output, EventEmitter } from "@angular/core";
 
 import { I18nService } from "../../services/internationalisation.service";
-import { fv } from "../../util";
+import { fv, longestVarParam } from "../../util";
 import { MultiDimensionResults } from "../../results/multidimension-results";
 
 @Component({
@@ -40,13 +40,8 @@ export class VariableResultsSelectorComponent {
             // pre-extract variable parameters values
             this.varValues = [];
             // find longest list
-            this.size = 0;
-            for (let i = 0; i < this._results.variatedParameters.length; i++) {
-                const vs = this._results.variatedParameters[i].valuesIterator.count();
-                if (vs > this.size) {
-                    this.size = vs;
-                }
-            }
+            const lvp = longestVarParam(this._results.variatedParameters);
+            this.size = lvp.size;
             // get extended values lists for each variable parameter
             for (const v of this._results.variatedParameters) {
                 const vv = [];
diff --git a/src/app/formulaire/definition/form-compute-pab.ts b/src/app/formulaire/definition/form-compute-pab.ts
index 4a786c647eaf97626c9ec2a1bbbd1c01933b74b3..a0ebc6f32572291da7d54ffd92ded324a0c757ed 100644
--- a/src/app/formulaire/definition/form-compute-pab.ts
+++ b/src/app/formulaire/definition/form-compute-pab.ts
@@ -4,6 +4,7 @@ import { FormulaireDefinition } from "./form-definition";
 import { FormResultPab } from "./form-result-pab";
 import { FormCompute } from "./form-compute";
 import { NgParameter } from "../ngparam";
+import { longestVarParam } from "../../../app/util";
 
 export class FormComputePab extends FormCompute {
 
@@ -47,13 +48,8 @@ export class FormComputePab extends FormCompute {
         pabr.Z2 = [];
         if (varParams.length > 0) {
             // find longest list
-            let longest = 0;
-            for (let i = 0; i < varParams.length; i++) {
-                const vs = varParams[i].valuesIterator.count();
-                if (vs > longest) {
-                    longest = vs;
-                }
-            }
+            const lvp = longestVarParam(varParams);
+            const longest = lvp.size;
             // get extended values lists for Z2
             if (pab.prms.Z2.hasMultipleValues) {
                 const iter = pab.prms.Z2.getExtendedValuesIterator(longest);
diff --git a/src/app/results/var-results.ts b/src/app/results/var-results.ts
index 48038a9c60c9610dc522f095f600d22990449666..72664aea53f4648cc6c90dde0e9fec560a89ed8c 100644
--- a/src/app/results/var-results.ts
+++ b/src/app/results/var-results.ts
@@ -8,6 +8,8 @@ import { ChartType } from "./chart-type";
 
 import { sprintf } from "sprintf-js";
 
+import { longestVarParam } from "../util";
+
 export class VarResults extends CalculatedParamResults implements PlottableData {
     /**
      * paramètres variés
@@ -333,16 +335,9 @@ export class VarResults extends CalculatedParamResults implements PlottableData
         });
 
         // liste la plus longue
-        this.size = 0;
-        let i = 0;
-        for (const v of this._variatedParams) {
-            const s = v.valuesIterator.count();
-            if (s > this.size) {
-                this.size = s;
-                this.longest = i;
-            }
-            i++;
-        }
+        const lvp = longestVarParam(this._variatedParams);
+        this.size = lvp.size;
+        this.longest = lvp.index;
 
         // result keys (extra or not) - some lines might miss some results, in case of an error;
         // use those keys to ensure all columns are filled
diff --git a/src/app/util.ts b/src/app/util.ts
index e4d3e1f1bf9eecaf247a42521ae971bdaf86320f..73ca8da3a937697f6e0aded347fe3dbea0eab23c 100644
--- a/src/app/util.ts
+++ b/src/app/util.ts
@@ -41,3 +41,27 @@ export function decodeHtml(html: string): string {
     txt.innerHTML = html;
     return txt.value;
 }
+
+/**
+ * Given a list of variated NgParameter, returns the parameter having the most
+ * values, its index in the list, and the number of values it contains
+ * @param varParams
+ */
+export function longestVarParam(varParams: NgParameter[]): { param: NgParameter, index: number, size: number } {
+    let i = 0;
+    let longest = 0;
+    let size = 0;
+    for (const v of varParams) {
+        const s = v.valuesIterator.count();
+        if (s > size) {
+            size = s;
+            longest = i;
+        }
+        i++;
+    }
+    return {
+        param: varParams[longest],
+        index: longest,
+        size: size
+    };
+}