3 Replies Latest reply: Jun 18, 2011 4:30 AM by Johan Idh RSS

    how to use a for loop in expression for a chart



      I have a requirement where I have to loop though the avaiable selections from a list box, and then do a calculation.

      Can some one please guide me on how to use the for loop in the edit expression box of a chart.



        • how to use a for loop in expression for a chart
          Nagaian Krishnamoorthy

          I think that the 'for loop' calculation is not available for use in the edit expression box. However you can use set analysis expressions.


          If your calculations are complex, it is advisabe to do them in the load script. If the calculations depend on the selections made by the user, you need to become creative. You can group your calculations into two parts, user-input-independent and user-input-dependent. In the user-input-independent group, you should try to calculate either the final results to display/use in the charts/chart-expressions or intermediate results for use by the user-input-dependent group to arrive at the final numbers for use in the charts/chart-expressions.


          Hope this helps.

          • Re: how to use a for loop in expression for a chart
            John Witherspoon

            Right, you don't do a for loop in an expression.  You're thinking procedurally, which is not how the expressions operate.  But your answer MIGHT be trivial.  If, for instance, you had a chart with customer as the dimension, and you wanted to execute this for loop in every cell in the chart:


            total quantity = 0

            for each order that the customer on this row has placed
                add ordered quantity to total quantity
            display total quantity


            That's just this expression:


            sum("ordered quantity")


            That's probably not what you're asking, but you're going to have to be a lot more explicit if you want anyone answering your question to be more explicit.