Search code examples
qlikviewconditional-expressions

How to write an expression for two different attributes in the same field in qlikview


Please help me write the script for the following statement in qlikview which I have it in SQL.

SELECT CASE
           WHEN Total_A=0 THEN 0
           ELSE cast(((Total_B+Total_C)/Total_A) AS decimal (5,2))
       END AS ratio

I have Total_A , Total_B and Total_C in the same field called Total_val


Solution

  • The SQL CASE is usually replaceable by the QlikView if().

    Try this

     if(Total_A=0,0,(Total_B+Total_C)/Total_A) as Ratio
    

    if the A,B,C switch is inside the Val column then it will get a lot more tricky as you will have to aggregate and use nested ifs. But I believe the statement I wrote is equivalent to the SQL you gave us. If my answer doesn't work please give us a few rows of data to look at