Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
vanderson009
Creator III
Creator III

Script Logic

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

2 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

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

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
aveeeeeee7en
Specialist III
Specialist III

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