Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Make a division in loadscript

Hello,

i've a problem reading data in my table and calculating percent. When i tried this (totalAmount is 8324,76):

LEFT JOIN GROUP_TIMES_COMP:

          LOAD

          tAmount / $(totalAmount) * 100 as percent

          RESIDENT GROUP_TIMES_COMP;

I got new colums named "tAmount / 8324" and "percent". The colum "tAmount / 8324" stores the divided values (tAmount/8324) - but i wanted to get this value multiplied by 100 in the colum "percent".

The colum "percent" stores always "7600" which seems to be the decimal place of $(totalAmount) multiplied with 100.

I tried anything, but could not resolve this yet. Anyone knows the solution?

5 Replies
er_mohit
Master II
Master II

try this

tAmount /( $(totalAmount) * 100) as percent

or

(tAmount /$(totalAmount) )* 100 as percent

or

div(tAmount ,$(totalAmount) )* 100 as percent

Not applicable
Author

LOAD

        ( ( tAmount / $(totalAmount) )* 100)   as percent

          RESIDENT GROUP_TIMES_COMP;

Not applicable
Author

Er.mohit give to you a right answer :

In your code, you multiply the total before divising.

(tAmount / $(totalAmount)) * 100

Not applicable
Author

yes,

you can try

(tAmount / $(totalAmount)) * 100


Not applicable
Author

I found the solution. The problem is decimal place of totalAmount and tAmount. This one works and is good enough for the project:

     ceil(tAmount)/ceil($(totalAmount)) * 100 as percent

All other ways i tried gives an error or 0-values in colum percent:

>>>

Error in expression:

')' expected

LEFT JOIN GROUP_TIMES_COMP:

          LOAD

          tAmount/( 8324,76 * 100) as percent

          RESIDENT GROUP_TIMES_COMP

 

Error in expression:

')' expected

LEFT JOIN GROUP_TIMES_COMP:

          LOAD

          (tAmount/8324,76) * 100 as percent

          RESIDENT GROUP_TIMES_COMP

 

Error in expression:

Div takes 2 parameters

LEFT JOIN GROUP_TIMES_COMP:

          LOAD

          div( tAmount, 8324,76 ) * 100 as percent

          RESIDENT GROUP_TIMES_COMP

<<<

If anyone knows how to divide with decimal place in divisor - feel free to post it!

Thank you for your notably fast response.