I’m new to Uipath and I don’t know where to give this query. I got trial version today and I have to analyse and give a demo tomorrow. I’m able to fetch the data from excel sheet and copy into another. While copying where I have to give the above query to get the summed output. Could you please help me on this?
Just change the name of the column based on which you have to group and name of the column of the price to get the Sum. Use the below query in Assign activity
Dictionarty=( From p in dta.Select
group p by Department=p.Item("PRODUCT") Into GroupA=Group
Select GroupA).ToDictionary(Function(x) x(0)("PRODUCT").ToString, Function(x) Convert.ToString(x.Sum(Function(y) Convert.ToDouble(y.Item("PRICE").ToString))))
Dictionary is the variable of Dictionary(Of string, String) dta is your Excel Sheet, stored in a datatable by using Read Range Activity.
Now you can access the the total sum of the product by like this
Dictionary(“Mobile”) to get the total sum of price of mobile category. and it will return 7000 as per your Example.
Could you please check whether this is correct. I have attached the screenshot of query and requirement in attached image. Could you please check on this?
@MAHESH1
In above example we are summing up total “WorkHr” right. if there is any empty row in that column its throwing the error.“Input string not found”
and using below query, since i have a null value in price its throwing the error.How to handle it.
Dictionarty=( From p in dta.Select
group p by Department=p.Item(“PRODUCT”) Into GroupA=Group
Select GroupA).ToDictionary(Function(x) x(0)(“PRODUCT”).ToString, Function(x) Convert.ToString(x.Sum(Function(y) Convert.ToDouble(y.Item(“PRICE”).ToString))))
( From p In Dt1.Select
Group p By Product=p.Item(“Product”) Into GroupA=Group
Select GroupA).ToDictionary(Function(x) x(0)(“Product”).ToString, Function(x) Convert.ToString(x.Sum(Function(y) Convert.ToDouble(y.Item(“Balance”).ToString))))
( From p In Dt1.Select
Group p By Product=p.Item(“Product”) Into GroupA=Group
Select GroupA).ToDictionary(Function(x) x(0)(“Product”).ToString, Function(x) Convert.ToString(x.Select(Function(z) Where not string.IsNullOrEmpty(z("Balance").ToString).Sum(Function(y) Convert.ToDouble(y.Item(“Balance”).ToString))))
Please add this Select(Function(z) Where not string.IsNullOrEmpty(z(“Balance”).ToString) It will select only rows which are not empty
Or try like this also
( From p In Dt1.Select
where not string.IsNullOrEmpty(p.Item("Balance").ToString)
Group p By Product=p.Item(“Product”) Into GroupA=Group
Select GroupA).ToDictionary(Function(x) x(0)(“Product”).ToString, Function(x) Convert.ToString(x.Sum(Function(y) Convert.ToDouble(y.Item(“Balance”).ToString))))