2 Replies Latest reply: Jul 31, 2014 7:24 AM by AVIRAL NAG RSS

    Script Logic

    Villyee Anderson

      Hi Community,

       

      What is difference between these two logic, even then given same output.

       

      LOAD Category,

                Spent,

                if(Category = 'car maint.' or Category = 'haircut' or Category = 'misc.','Non-Recurring Spent','Recurring Spend') as Category_Type

      Resident Test;

       

       

      LOAD Category,

                Spent,

                if(Category = 'car maint.' or Category = 'haircut' or Category = 'misc.',

                Dual('Non-Recurring Spent',1), Dual('Recurring Spend',0)) as Category_Type

      Resident Test;

       

      -- Thanks and Regards,

      Villyee Anderson

        • Re: Script Logic
          Jonathan Dienst

          Hi

           

          The output is not the same. The first produces Category_Type as a normal text field. The second returns Category_Type as a numeric field with values 0 and 1, and with display representations as defined in the dual command.

           

          The advantage of duals is that you can sort them numerically, like Month() which sorts correctly in month order and not alphabetically.

           

          HTH

          Jonathan

          • Re: Script Logic
            AVIRAL NAG

            Dual() Function is used to forcefully assign a number to Text Field.

             

            Here, In 1st Code, you are Hardcoding the cases based on conditions and it is coming in Text Format.

             

            In 2nd Code, You are doing the same thing but only difference is that you are using Dual() function which forcefully convers the Text 'Non-Recurring Spent' & 'Recurring Spend' to Number. When you Sort this Field Category_Type, it will Sort in the Assigned Numbers Orders. Eg.  'Recurring Spend' comes first since it has been assigned Number 0 and then comes 'Non-Recurring Spent' which has been assigned number 1.

            This happens when you do Sorting in Ascending Order.

             

            Hope that clears some of your doubts.

             

             

            Regards

            Aviral Nag