Search code examples
tableau-apitableau-desktop

How can we implement the same condition with two different values in tableau?


    IF [District Parameter] = "All"  THEN  [routes]

   ELSEIF  [District Parameter] = "BARGARH" and [Name of the Recipient District1] = 
   "Khordha" THEN [c.origin to depo route]

   ELSEIF [District Parameter] = "BARGARH" and [Name of the Recipient District1] = 
  "Khordha"
   THEN [c.depo to receipent route]  

  ELSEIF [District] = [District Parameter] THEN [routes]

   END

In the above code [routes], [c.depo to receipent route] and [c.origin to depo route] are spatial calculated fields. You can see two elseif conditions have the same condition with two different values. But When I executed the above code only one elseif condition is getting executed. Kindly give some solution, I want to implement both elseif conditions with two different values.


Solution

  • In single calculation it is difficult to achieve. Not sure of the question though. You need to create some flag to distinguish between 2 elseif.

    Below solution you can try.

    create 3 calculated field to achieve this.

    calculated field1- IF [District Parameter] = "All" THEN [routes]

    ELSEIF [District Parameter] = "BARGARH" and [Name of the Recipient District1] = "Khordha" THEN [c.origin to depo route]

    ELSEIF [District] = [District Parameter] THEN [routes]

    END

    calculated field2-

    IF [District Parameter] = "BARGARH" and [Name of the Recipient District1] = "Khordha" THEN [c.depo to receipent route]

    END

    calculated field3-

    if isnull(field1) then field2 else field1 end

    Display field3.