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.
Thanks in advance.
In general a Group By Case which we can handle as described here:
This HowTo introduces on the different options for grouping data from a datatable in order to process the grouped data.
Grouping data and processing the grouped data is a common scenario e.g. when the grouped data is to aggregate like summing up, find maximum, get the average or concatening items.
Lets have a look on following data:
A possible scenario could be:
Create a report containing following information:
the region code
the sum of CaseCount per RegionCode
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
outer List = Groups, inner List = Group Members
For Each Activity (not for each row activity) | grp = Groups | TypeArgument: List(Of DataRow)
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?
for further studies also have a look here:
This HowTo gives an introductory overview of the aggregation Operators: Min, Max, Sum, Average
The aggregation operators are used to retrieve from a collection a particular result by setting the contained items into a relationship.
I – Input
P – Processing
O – Output
get the lowest value
get the highest value
sum up all values
get the average of all values
So, there will be 2 for each? One inside another?
@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
hat is the role of F2
Acting like a local loop variable. Reflecting the looped group member datarow.
We shared some links and also described it here:
LINQ is part of the .NET framework and offers capabilities for interacting with data, objects or other sources within a particular syntax.
This HowTo introduces on starting with LINQ (Language-Integrated Query).
Current Version of this topic is DRAFT and will be finalized / enhanced soon
Typical tasks for implementing parts of an automation project are interacting with e.g. with data in a datatable or items from collections. LINQ can help to implement it into a compact and standa…
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
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.