Assigning index variable to mixed data elements in a Dt

Hi…I am down a rabbit hole here on a complex automation. I have a data table with items similar to this:
image

I need to assign a sequence number based on different type and different date span. For example, the earliest extension would have sequence of 1, second extension would have sequence of 2. The earliest option would have sequence of 1, and so forth. I thought about indexing but having difficulty getting the indexes to take into account date as well as type. Thought maybe a LINQ? Anyone have any thoughts?

Chris

Hi @Chris_Bolin

In order to get the correct order, I have this workaround in my mind to use the Rank Function on all 3 Columns and Sum all the Ranks that you get from these 3 and then sort it in ascending.

Lets Call it Cumulative ranking and make it work!

Thanks

Happy Automation! :smiley:

you could group the data with a group by and then looping over the groups and set the index

myGroups | List(Of List(Of DataRow)) =

(From d in YOurDataTableVar.AsEnumerable
Group d by k=d("Type").toString.Trim into grp=Group
Select g=grp.ToList).toList

outer list items are the groups, inner list items are the group members

  • For each -Activity | grp in myGroups | TypeArgument: List(of DataRow)
    • For each - activity | mbr in grp | TypeArgument: DataRow - index = idx
      • Assign Activity: mbr(“Sequence”) = (idx + 1) .toString

Solve this myself with filter and sort by date then (dt.rows.indexof(rows) +1).toString where the variable index is assigned to 0 with an output of the result to a row item variable…sometimes stepping away and sleeping helps one get out of a rabbit hole

1 Like

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