Linq with if Condition and Datatable Update

Hi Team,

I have a datatable that contains various columns. Now, some of the columns are Invoice Number, Material, Price etc etc.
I am facing an problem while writing a linq, the condition being if Invoice Number and Material both are same then i need to avg the price and write in all the places. Like if One invoice number is present in 3 rows and all three rows are having same material then we need to avg the price in the 3 rows and fill in the price column of all the three rows.

For example,
Input:
image

Output:
image

Thanks in advance.

In general a Group By Case which we can handle as described here:

We would recommend to start with a hybrid approach

Groups | DataType: List(of (ListOf DataRow)) =

(From d in dtData.AsEnumerable
Group d by k1=d("InvoiceNo.").toString.Trim, k2=d("MATERIAL CODE.").toString.Trim into grp = Group
Select x=grp.ToList).toList

outer List = Groups, inner List = Group Members

For Each Activity (not for each row activity) | grp = Groups | TypeArgument: List(Of DataRow)

  • Assign Activity
    strAVG = grp.Average(Function (x) CDbl(x(“Price”).toString.Trim)).toString(“F2”)

  • For Each Activity (not for each row activity) | mbr in grp | TypeArgument: DataRow

    • Assign Activity: mbr(“Price”) = strAVG

When DataColumn Price defines a Not Object/String Datatype then we just would little adapt

Could not understand properly about that Assigns activities, can you elaborate that or send a screenshot of UiPath studio screen with these steps?

e.g
grafik

for further studies also have a look here:

So, there will be 2 for each? One inside another?

hey @ppr , how is this happening? I mean, we are modifying the dt_?list but how come the datatable is getting modified on its own? and what is the role of F2 in strAVG = grp.Average(Function (x) CDbl(x(“Price”).toString.Trim)).toString(“F2”)

initial it should look like this

each datarow is belonging to its datatable and is referencing it via the Navigation Property: Table. So when working with the datarow it is also relected within the datatable

Acting like a local loop variable. Reflecting the looped group member datarow.

We shared some links and also described it here:

Experiments can be done e.g. within the immediate panel
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

We hope you can finalize the modelling and the topic can be closed:
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

@yash.choursia
can the topic be closed?
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

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