Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
ss09
Contributor III
Contributor III

Custom Function Creation

How can I create my own Function in Qlik - I having to repeat this logic over and over?
=Num(Sum(population_baseline_pop_psd)*1000, vDecimalTwoPlaces, vDecimalSep, vThousandSep)

Where vDecimalTwoPlaces, houses 2 number formats based on the language selected. Similary for the Seperators.
I want to make it so that I can do something like:
SuperNum2(Sum(population_baseline_pop_psd)*1000)

Where SuperNum2 - has all these attributes set for cleaner code: vDecimalTwoPlaces,, vDecimalSep, vThousandSep

Labels (1)
4 Replies
vincent_ardiet_
Specialist
Specialist

You have to create a new variable called "SuperNum2" containing 
=Num($1, vDecimalTwoPlaces, vDecimalSep, vThousandSep)

ss09
Contributor III
Contributor III
Author

ss09_0-1701188382633.png

vNumTwo=vDecimalTwoPlaces

 

vincent_ardiet_
Specialist
Specialist

Yes, the variable will be seen as invalid by QS.
Else, sorry, I have done a mistake in my copy/paste, the equal should not be in the variable definition.
So, you define SuperNum2 with Num($1, vNumTwo, vDecimalSep, vThousandSep)
Then, you use it with $(SuperNum2(Sum(population_baseline_pop_psd)*1000))

Ahidhar
Creator III
Creator III

try this 

set vDecimalTwoPlaces='#,###.00';
set vDecimalSep='.';
set vThousandsep=',';
set SuperNum2=num($1,'$(vDecimalTwoPlaces)','$(vDecimalSep)','$(vThousandsep)');
Tab:
load *,$(SuperNum2(Value)) as num;
load * inline
[ Value
100.18
10000
28837.1
];