Adding duplicate rows to DataTable based on certain values

Hi everyone,

After screenscraping from a web table, I’m trying to add new rows to the extract datatable based on the values in the DFF Identifier column. These new rows should also inherit certain relevant row values.

Perhaps an example would make this clearer…

The raw extract datatable looks something like this:

This is what the output should look like:
image

any ideas how to use UiPath to achieve this result?

I would really appreciate any help on this as I’ve been stuck on this for days now.

Thank you :slight_smile:

from where should come 4688 (output austria) come from, as we dont see it in the input table

Hey @ceceliaa34!!! I can give you a quick, unsophisticated, not-so-optimized answer. Simply to unburden the time you are stuck in this solution. Then we thought of something optimized and functional.

Hi,

Can you try the following sample?

img20220216-5

dt = dt.AsEnumerable.SelectMany(Function(r) if(String.IsNullOrEmpty(r("DFF Identifier").ToString),{r},r("DFF Identifier").ToString.Split(","c).Select(Function(s) dt.Clone.LoadDataRow({s,r("COUNTRY").ToString,""},False) ).ToArray)).CopyToDataTable()

Sample20220216-3.zip (9.6 KB)

Regards,

2 Likes

Just tried this, it works!
Thank you so much.

One last question please - if I wanted to clone more columns to the output file, example below - how do I edit the code to give results similar to the below

UNIQUE ID COUNTRY DFF Identifier VO CODE POST CODE
HGTRP AUSTRIA 1 XX
HFFRT GERMANY HFFRT,HKKIY 11 XXX
HKKIY GERMANY HFFRT,HKKIY 11 XXX
PLNGGE POLAND PLNGGE,PLNHGFC,PLN4F,PLMNBGD 1111 XXXX
PLNHGFC POLAND PLNGGE,PLNHGFC,PLN4F,PLMNBGD 1111 XXXX
PLN4F POLAND PLNGGE,PLNHGFC,PLN4F,PLMNBGD 1111 XXXX
PLMNBGD POLAND PLNGGE,PLNHGFC,PLN4F,PLMNBGD 1111 XXXX
MXU896 MEXICO 111111 X
EST544 ESTONIA EST544,ESTR5HFF,ESTNHGQ 11111 XXXXX
ESTR5HFF ESTONIA EST544,ESTR5HFF,ESTNHGQ 11111 XXXXX
ESTNHGQ ESTONIA EST544,ESTR5HFF,ESTNHGQ 1111 XXXXX

Appreciate your help! :slight_smile:

Hi,

Please add items in argument of LoadDataRow method in the above expression, as the following.

LoadDataRow({s,r("COUNTRY").ToString,"",r("VO CODE").ToString,r("POST CODE").ToString},False)

Can you try this?

Regards,

Amazing! Works like a charm!!!

thank you so much :smiley:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.