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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

duplicate row based on number value

Hello,

please could you help me with below query. I want to duplicate row based on a stock value.  my input will be from excel file

 

input :

 

Item   Description   stock  Location

Tea     Drink            350    shelf1

 

I want to divide stock with 100 so I can make 4 rows like output below.

 

output if stock less than 100

Item   Description   stock  Location

Tea     Drink            100    shelf1

 

output if stock more than 100

Item   Description   stock  Location

Tea     Drink            100    shelf1

Tea     Drink            100    shelf1

Tea     Drink            100    shelf1

Tea     Drink             50    shelf1

 

Thanks.

 

Labels (1)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi,

I got a solution, probably is not optimized but it's work.

0683p000009LsKU.png

Result for a row with 450 stock

0683p000009LrDa.png

 

TJavaflex_2 Code :

int Loop = Mathematical.SDIV(((Integer)globalMap.get("row5.stock")) , 100);
if(((Integer)globalMap.get("row5.stock")) % 100 > 0)
{
    Loop = Loop + 1 ;
}
globalMap.put("LOOP", Loop);

 

tLoop Parameter

0683p000009LsKZ.png

 

tJavaFlex_3 Code :

row7.item = ((String)globalMap.get("row5.item"));
row7.desc = ((String)globalMap.get("row5.desc"));
row7.location = ((String)globalMap.get("row5.location"));

if
(((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))==((Integer)globalMap.get("LOOP")))
{    
    if(((Integer)globalMap.get("row5.stock")) % 100!=0)
    {
        row7.stock = ((Integer)globalMap.get("row5.stock")) % 100;
    }
    else
    {
        row7.stock = 100;
    }
}
else
{
    row7.stock = 100;
}

 

 

 

Good luck ,

SGV

View solution in original post

1 Reply
Anonymous
Not applicable
Author

Hi,

I got a solution, probably is not optimized but it's work.

0683p000009LsKU.png

Result for a row with 450 stock

0683p000009LrDa.png

 

TJavaflex_2 Code :

int Loop = Mathematical.SDIV(((Integer)globalMap.get("row5.stock")) , 100);
if(((Integer)globalMap.get("row5.stock")) % 100 > 0)
{
    Loop = Loop + 1 ;
}
globalMap.put("LOOP", Loop);

 

tLoop Parameter

0683p000009LsKZ.png

 

tJavaFlex_3 Code :

row7.item = ((String)globalMap.get("row5.item"));
row7.desc = ((String)globalMap.get("row5.desc"));
row7.location = ((String)globalMap.get("row5.location"));

if
(((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))==((Integer)globalMap.get("LOOP")))
{    
    if(((Integer)globalMap.get("row5.stock")) % 100!=0)
    {
        row7.stock = ((Integer)globalMap.get("row5.stock")) % 100;
    }
    else
    {
        row7.stock = 100;
    }
}
else
{
    row7.stock = 100;
}

 

 

 

Good luck ,

SGV