Add data to a specific column using an array of string values

I have an array of location with 6 values lets say arr_locations= [“A”,“B”,“C”,“D”,“E”,“F”] and a datatable variable which already has some data. Lets say this datatable has 3 rows so every location must be mapped to these 3 rows.
That means at the end the total rows in my datatable would be 3*6 = 18 rows.

i/p:

o/p:

Attaching test file for your reference. Sheet1 is input & Sheet2 is the expected Output.
Testing.xlsx (10.0 KB)

@SunnyJha

  1. Read range and read data of 3 rows
  2. For each on list with arr.Take(arr.Count-1)
  3. inside loop use append range with the table read in step 1

cheers

we are depended on the col structures
assumption: Project set to Windows

Variable:
arr_locations = {“A”,“B”,“C”,“D”,“E”,“F”}

Assign Activity:
dtResult = dtOrig.Clone

Assign activity:
dtResult =

(From d in dtOrig.AsEnumerable
From lo in arr_locations 
Let ra = d.ItemArray.SkipLast(1).Append(lo).Cast(Of Object).toArray
Order by lo
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

UPD1 - Bracket Fix
UPD2 - Beautified it with an adtional ordering
grafik

1 Like

Hi @SunnyJha

Can you try the below

Sequence.xaml (15.8 KB)

Ouput:

Testing.xlsx (11.2 KB)

Regards,

I also have to mention that if you look at the last column Description which is empty in input and in the output has values from the array. That’s the main crux.

Hi @ppr ,
If you see the image I also have to assign the locations in the Description column.

we had handled this within the Linq (SkipLast(1).Append… part

1 Like

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