Question T3669
Visible to All Users

Calculate Expression Query

created 5 years ago

Hello,

We are looking at the calculate expression and can see in an example there is 'sumInArray'. What we are requiring is a 'maxInArray' - does such a function exist?

Is there a list of calculate expression functions to reference to?

Kind regards
Chris

Answers approved by surveyjs Support

created 5 years ago

Hello Chris,
Yes, this function exists. Here is our docs.

Thank you,
Andrew
SurveyJS Team

    Comments (3)

      Thank you Andrew,

      However, I can quite configure what I need it to.

      What I want is the maximum value in these three values: max({panel.PeopleScore}, {panel.AssetsScore}, {panel.ReputationScore}) the equivalent of the Javascript Math.max() method.

      Do you have an example of the maxInArray function?

      Kind regards
      Chris

        Hello Chris,
        To my surprise we do not have a common max, min and sum functions. I think we will add them into the library.
        Here is the function that you can use for now:

        JavaScript
        function survey_max(params) { if(!params || !Array.isArray(params)) return undefined; var res = undefined; for(var i = 0; i < params.length; i ++) { var v = params[i]; if(v == null || v == undefined) continue; if(res == undefined || res < v) { res = v; } } return res; } Survey.FunctionFactory.Instance.register("max", survey_max);

        Here is the working example.

        Thank you,
        Andrew
        SurveyJS Team

          FYI: Function min and max will be available from v1.5.19. Here is the related issue on GitHub.

          Thank you,
          Andrew
          SurveyJS Team