2 Replies Latest reply: Jan 15, 2013 9:51 AM by Jonathan Brough RSS

    If and Sum - different results

    Nils Andersen



      Why do these 2 expressions give different results?     Currency is in a separate table and not associated with other tables.



      sum({<Year=,Quarter=,Month=>} if(Currency = ‘Local’, [Local Amount], [Group Amount]))



      if(Currency = ‘Local’,

          sum({<Year=,Quarter=,Month=>} [Local Amount])

          sum({<Year=,Quarter=,Month=>} [Group Amount]))



      The first expression gives the correct result - but I like the second expression the best




        • Re: If and Sum - different results
          jagan mohan rao appala

          I think you need to use Sum().  Try below expression.


          =Sum(if(Currency = ‘Local’,

              sum({<Year=,Quarter=,Month=>} [Local Amount])

              sum({<Year=,Quarter=,Month=>} [Group Amount])))





          • Re: If and Sum - different results

            My understanding is that when you use sum(if(.... your test and calculation is being run once for each datapoint. However, if you use if(sum(... then you are summing all the datapoints first, and then testing the result. This isn't what is usually required, as in this case where the currency is relevant to each Amount.

            I agree that if..sum feels more logical, but after a while sum .. if doesn't seems quite natural too.