Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Explain this Code?

Hi Guys,

I am new to Qlikview. Kindly Explain Below Code :

Dual(

Country & '-' &

Num(sum(Sales), '#,##0') &

Repeat(chr(13)&chr(10), rank(Sum(Sales))-6),

sum(Sales)

)

Table:

LOAD * INLINE [

Country, Sales

USA, 100000

Canada, 50000

Mexico, 25000

UK, 70000

Germany, 20000

Brazil, 15000

France, 10000

Japan, 9000

China, 8000

Australia, 7000

South Korea, 5000

New Zealand, 4000

Italy, 2000

];

I want know the code Complete Explanation.

3 Replies
ziadm
Specialist
Specialist

Hi

The Dual Function takes two parameters only.  What you have is 3 parameters which will result in an error.

Please check and revert back

Dual Function is mainly to Transform Text into integers numbers.  The use of Dual function is mainly for sorting Text in the right order such as months Jan-Dec or weekdays (Mon-Fri).  Other useful use of dual is to translate text into numbers for the purpose of calculations such as adding and summing

robert_mika
Master III
Master III

Dual(

Country & '-' &

Num(sum(Sales), '#,##0') &

Repeat(chr(13)&chr(10), rank(Sum(Sales))-6),

sum(Sales)

)

Dual is function by which you can assign number to Text

Please see more here:

How to use- Dual()

By using this function you can show Text by use underlay Number for calcualtions.

rank(Sum(Sales))-6) - is the rank of the Sales per country - 6

Repeat(chr(13)&chr(10) - is a new line(13) and carriage return (10) in ANSI code

But This part is not really much use:

Repeat(chr(13)&chr(10), rank(Sum(Sales))-6) as will only reapats the carriage return and new line so many times that the rank returns


Using only this part



Dual(Country & '-' &Num(sum(Sales), '#,##0') ,sum(Sales)


Will give you the same result


You can use that expression in chart or Textbox

Table:

LOAD * INLINE [

Country, Sales

USA, 100000

Canada, 50000

Mexico, 25000

UK, 70000

Germany, 20000

Brazil, 15000

France, 10000

Japan, 9000

China, 8000

Australia, 7000

South Korea, 5000

New Zealand, 4000

Italy, 2000

];

This is your table with data

Gabriel
Partner - Specialist III
Partner - Specialist III

Hi,

What this expression is say is,

The Dual Function takes two parameter, so the first part is give me each country with '-' and you're formatting sum of sales for each country as Num( '#,##0'). And you're using repeat function which takes 2 parameter as well,the first part of the repeat function is what to repeat which is a space and line-feed (Not used for anything much), the second part is how many time to repeat this you're using rank function of sum of Sales -6.

And Finally the second part of Dual function is Sum of Sales.


All this will return is Country and hyphen and Sales value.


I think this expression is not doing exactly what you want it to do. My suggestion is if you can explain what you want to achieve then community might be able to help.


And I also agree with what Robert_Mika  said