Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
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