7 Replies Latest reply on Oct 10, 2019 10:51 AM by Branden Kornell

    Conditional aggregation on tableau

    Emmanuel Sibanda

      Trying to create a conditional calculated field that looks at the value (actuals,targets,difference) of the dimension and divides costs by leads per value and then calculates the difference between these.

      This is my code:


      CASE [row_name]
      WHEN 'targets' THEN [t_spend]/[leads]
      WHEN 'actuals' THEN [t_spend]/[leads]
      WHEN 'difference' THEN (SUM(IF([row_name]='targets') THEN([t_spend]/[leads] - SUM(IF([row_name]='actuals') THEN([t_spend]/[leads]))END)



      This is my desired output:


                 cost leads c/lead
      targets      1000 10 100
      actuals       500 10 10
      diff          500 0 90