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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
idembel2
Creator
Creator

HOW TO MAKE THIS DEV

Morning All,

 

I have a csv file which look like that:

UserID;Work_Hours; Start_Date; End_Date 

1 ;     7    ;01/06/2017;01/06/2017    

;     14    ;01/06/2017;02/06/2017

3 ;     10    ;04/06/2017;05/06/2017

4;     19    ;05/06/2017;07/06/2017

This file show hours worked by person; and each day work equal 7 hours

So what i need to do is to check Work_Hours and if it is more than 7, i should duplicate the same line and put also correct value in Work_Hours column.

I need to get something like bellow:

UserID;Work_Hours; Start_Date; End_Date 

1 ;     7    ;01/06/2017;01/06/2017    

;     7    ;01/06/2017;02/06/2017

2 ;     7    ;01/06/2017;02/06/2017

3 ;     7    ;04/06/2017;05/06/2017

3 ;     3    ;04/06/2017;05/06/2017

4;     7    ;05/06/2017;07/06/2017

4;     7    ;05/06/2017;07/06/2017

4;       ;05/06/2017;07/06/2017

 

I don't know how to develop it, may somebody advice me how to do it

Thanks,

Labels (1)
1 Solution

Accepted Solutions
idembel2
Creator
Creator
Author

Hello Cterinzi,

 

I test your advice and let you know, i know it should work.

Thank you very much, 

View solution in original post

2 Replies
cterenzi
Specialist
Specialist

I would approach this in a manner similar to the solution offered in this link:
https://community.talend.com/t5/Design-and-Development/Split-one-row-into-multiple-rows-keeping-no-o...

 

I'd probably use tJavaRow to set up a while loop that builds a string:

int counter = input_row.Work_Hours;
StringBuilder outStr = new StringBuilder("");
if (counter > 7) {
outStr.append("7");
counter -= 7;
} else {
outStr.append(counter);
counter = 0;
}
while(counter > 0) {
if (counter > 7) {
outStr.append(",7");
counter -= 7;
} else {
outStr.append(",");
outStr.append(counter);
counter = 0;
}
}
output_row.Work_Hours = input_row.Work_Hours;
output_row.hoursList = outStr.toString();

You'll need to handle passing through the rest of your values, but the code above will create a comma separated list breaking up Work_Hours into 7's.  Send the output into a tNormalize component configured to normalize hoursList and it should create a separate row of output for each value in the list.

idembel2
Creator
Creator
Author

Hello Cterinzi,

 

I test your advice and let you know, i know it should work.

Thank you very much,