3 Replies Latest reply on Feb 3, 2019 4:09 PM by Ken Flerlage

    What is Tableau's alternative to the Visual Basic SWITCH function?

    vaughan.kirkby

      Hello,

      Sorry but I am new to all of this, both Visual Basic and Tableau.

       

      I have a Visual Basic SWITCH function that returns a value [Hours Worked] if the last 2 digits of a string are either; 04  05  or 70

       

      SUM(IIF(RIGHT([WBS Element],2) ="70" ,[Hours Worked ],0))/SUM(SWITCH (RIGHT([WBS Element],2), "70",[Hours Worked],"04",[Hours Worked],"05",[Hours Worked],0))

       

      In Tableau I have been able to write it as a nested IF

       

           SUM(IIF(RIGHT([WBS Element],2) ="70",[Hours Worked],0))/(SUM(IIF(RIGHT([WBS Element],2) ="70",[Hours Worked],0)) + SUM(IIF(ENDSWITH([WBS Element],"4"),[Hours Worked],0)) + SUM(IIF(ENDSWITH([WBS Element], "5"),[Hours Worked],0)))

       

      But this means that the code loops three times through each row and then sums them together.

       

      So to my question, is there a Tableau function that performs in the same/similar way to the Visual basic SWITCH function?