4 Replies Latest reply on Aug 21, 2018 9:32 AM by Terese Prascieniute

    Conditional aggregation or an aggregation on condition?

    Terese Prascieniute

      Hey guys,

       

      I find it hard to undersatnd what Tableau is 'thinking' when I create these too calculations, which to my head should return the same result.

       

      Here's my data:

      CountryMonth
      Metric
      A2017-11-01
      A2017-12-01
      A2017-12-011
      A2018-01-01
      A2018-02-01
      A2018-03-01
      A2018-03-011
      A2018-04-01
      A2018-04-011
      A2018-05-01
      A2018-05-011
      A2018-06-01
      A2018-06-011
      A2018-07-01
      A2018-07-011

       

      Now I have two calculations:

      1)

      IF max([Month]) = max({max([Month])})

      then sum([Metric])

      END

       

      2)

      sum(IF [Month] = {max([Month])}

      then [Metric]

      else null

      end)

       

      When I drag a single calculated field to the sheet, I get 6 if it is the first calculation, and 1 if it is the second calculation. I cannot comprehend why the two calculations should return different results.

       

      Thanks for any help!

       

      Terese