Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
Modernize Your QlikView Deployment webinar, Nov. 3rd. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
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
Highlighted
Master II
Master II

try this

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

or

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

or

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

Highlighted
Not applicable

LOAD

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

          RESIDENT GROUP_TIMES_COMP;

Highlighted
Not applicable

Er.mohit give to you a right answer :

In your code, you multiply the total before divising.

(tAmount / $(totalAmount)) * 100

Highlighted
Not applicable

yes,

you can try

(tAmount / $(totalAmount)) * 100


Highlighted
Not applicable

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.