3 Replies Latest reply on Nov 30, 2016 10:10 AM by Samantha Absher

    Error in "if" "else if" calculated field

    Samantha Absher

      I am super new to Tableau and am using to do a rather large analysis. I need to get a cost per lead for various campaigns. So, I need Sum of Cost/Sum of Leads but the column that the lead is pulled from will vary depending upon the campaign. Here is a simplified example of my data:


      DateAssigned CampaignCampaign A LeadsCampaign B LeadsCampaign C LeadsCost
      1/1/2016Campaign A113
      1/2/2016Campaign B355
      1/3/2016Campaign C532
      1/4/2016Campaign A328
      1/5/2016Campaign B762
      1/6/2016Campaign C275
      1/7/2016Campaign A747
      1/8/2016Campaign B221
      1/9/2016Campaign C957


      Based on my limited experience, I thought the "if" and "elseif" function would work:

      IF CONTAINS([Assigned Campaign], "Campaign A") THEN SUM([Cost])/SUM([Campaign A Leads])

      ELSEIF CONTAINS([Assigned Campaign], "Campaign B") THEN SUM([Cost])/SUM([Campaign B Leads])

      ELSEIF CONTAINS([Assigned Campaign], "Campaign C") THEN SUM([Cost])/SUM([Campaign C Leads])




      I keep getting one of two errors:

      Syntax Error (maybe you are missing an identifier)
      Cannot mix aggregate and non-aggregate comparisons or results in "IF" expressions.


      Like I mentioned, I'm super new at this and I would really appreciate some help! Thanks!