Convert datatable from excel to dictionary

Hello!
I have this kind of datatable and the number of rows is variable.

|ITEM NUMBER|PO NUMBER|QTY|MEASURE UNIT|DELIVERY DATE|

|437|440025955|200 |db|22.07.2022|
|435|440025955|300|db|22.07.2022|
|342|441231233|100|db|22.07.2023|
|121|561231234|60|db|22.07.2024|

What i need it to convert this to a dictionary with the PO NUMBER being the key and the rest of the lines where this number is present to be converted in a datatable as value for this dict.

EX:
{
key: “440025955”, value:
|ITEM NUMBER|QTY|MEASURE UNIT|DELIVERY DATE|
|437|200|db|22.07.2022|
|435|300|db|22.07.2022 | ;

key: “441231233”, value:
|ITEM NUMBER|QTY|MEASURE UNIT|DELIVERY DATE|
|342|100|db|22.07.2023| ;

key: “561231234”, value:
|ITEM NUMBER|QTY|MEASURE UNIT|DELIVERY DATE|
|121|60|db|22.07.2024| ;
}

Thank you!

please follow this solution

1 Like

Hi @Andrei_Croitoru

You can try this

image

(From row In dt_Data
Group row By k = row("PO NUMBER").ToString.Trim
Into grp=Group
Let tup = Tuple.Create(Of String, System.Data.DataTable)(k, grp.CopytoDataTable.DefaultView.ToTable(False, ColumnNames.Except({"PO NUMBER"}).ToArray))
Select tup).ToDictionary(Function(k) k.Item1, Function(v) v.Item2)

xaml for reference

DataTableToDict.xaml (5.8 KB)

2 Likes

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