Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

loop on a condition

Hi team,


I want to distribute the attribute "number" by 1 on the attributes "Supp" which have the biggest "rest" and which are grouped by code,
I use:
tOracleInput-> tSortRow-> Tjavaflex-> tLogRow

I use tSortRow to sort the "rest" attributes,

tJavaFlex:
for (int i = 0; i <= row7.code; i ++)
{for (j = 0; j <= row7.number; j--)
     
{row10.Supp = row7.Supp + 1;}

 

input
code|number|rest|supp
1 |2 |150 |4
1 |2 |125 |1
1 |2 |110 |1
2 |3 |145 |0
2 |3 |130 |3
2 |3 |50 |1
2 |3 |10 |4
Iwant an output like this:
code|number|rest|supp
1 |2 |150 |5
1 |2 |125 |2
1 |2 |110 |1
2 |3 |145 |1
2 |3 |130 |4
2 |3 |50 |2
2 |3 |10 |4


Could anyone please give me a hint of how to do this?

Your help is very much appreciated.


thanks,

nadakh

Labels (1)
16 Replies
Anonymous
Not applicable
Author

Find attached the job

 

Here is the tJavaRow

String code = input_row.code;
int num = input_row.number;

output_row.code = input_row.code;
output_row.number = input_row.number;
output_row.rest = input_row.rest;
output_row.supp = input_row.supp;

if( code.contains(context.current_code) ){
	context.to_distribute -= 1 ;
	output_row.supp += ( 0 > context.to_distribute ? 0 : 1 );
} else {
	context.current_code = input_row.code;
	context.to_distribute = input_row.number - 1;
	output_row.supp += ( 0 > context.to_distribute ? 0 : 1 );
}

hope this will help

 


DEMO_INTEGRATION.zip
Anonymous
Not applicable
Author

0683p000009M4M5.png

l have this error when I set the context.to_distribute

Anonymous
Not applicable
Author

Please, import the job I send to you and first test it

Then try to see how you can replicate on your job
Anonymous
Not applicable
Author

Thank you,  It works well . 

 

I have another problem.  

for the same procedure , I have the calculation expression : "rest"= A/(B+1)

but each time I recalculate the rest that got a number as follows: "rest"= (A/(B+1 +1)) (adding 1 )

and I start again until the "number" is distributed all.

 

Anonymous
Not applicable
Author

Sorry, don't understand

What's A and B ?
If you add screenshot, it might help
Anonymous
Not applicable
Author

reste=Voix/(supp+1)

for exemple, for code1: "number" to distribute =2

1) for "rest" = 584 / (2+1)=194.66 
    for "rest" = 840 / (3+1) =210 
    for "rest" = 863 / (3+1) =215.75 we assign a "Number"=1 -> Supp = Supp+1 ( because 215,75 is the max)

2) for "rest" = 584 / (2+1)=194.66 
    for "rest" = 840 / (3+1) =210 we assign a "Number"=1 -> Supp = Supp+1 ( because 210 is the max)

    for "rest" = 863 / (3+1+1) =172.6

result:

code|Supp

   1   |   2

   1   |  4  (3+1)

   1    |  4 (3+1)  

and we repete for each group of code the same procedure precedent

 

 

Anonymous
Not applicable
Author

I try this code in tjavaRow but it doesn't works:

//Code généré selon les schémas d'entrée et de sortie
output_row.code = input_row.code;
output_row.number = input_row.number;
output_row.VOIX = input_row.VOIX;
output_row.supp = input_row.supp;
output_row.rest = input_row.rest;


String code = input_row.code;
int num = input_row.number;
double reste =Double.valueOf(input_row.VOIX/(input_row.supp+1+1));

if( code.contains(context.current_code) ) and (context.reste<input_row.rest) {
context.to_distribute -= 1 ;
output_row.supp += ( 0 > context.to_distribute ? 0 : 1 );

} else {
context.current_code = input_row.code;
context.to_distribute = input_row.number - 1;
context.reste= Double.valueOf(input_row.VOIX/(input_row.supp+1+1));
output_row.supp += ( 0 > context.to_distribute ? 0 : 1 );
}

please I need your help to resolve this