Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

vanderson009
Not applicable

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
jontydkpi
Not applicable

Re: Script Logic

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
Not applicable

Re: Script Logic

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