Hi, I have a filtered datatable that when is put in a new excel file (through write range) looks like this :
Column A : name of the companies
Column B : Invoices ID
Column C : value of the invoices
Basically I have the first 7th rows with the same company(cells A1-A7), with different invoices(cells B1-B7) of different values (cells C1-C7), then the same stuff for the following 4th rows with another company that in turn has different invoices of different values and so on… I do like it but my question is : instead of creating an excel like this, wouldn’t be possible to tell "create an excel file that directly spend 1 full row(instead of 7 or 4 as mentioned before) dedicated to a SINGLE company where
Column A would be the name of the company (A1)
Column B: total number of Invoices of that company (B1)
Column C: total value of the Invoices present in column B (C1)?
I am quite new to uipath and programming in general, so i feel like i have to do some sort of "for each Row in data table " activity but don’t know exactly what to put in the body. .
Thanks in advance
Can you share the excel file or the screenshot of the scenario? Kind of confused in understanding that.
Just for your reference:
Once you read the excel using Write range then you can loop using for each data row. Inside that you can assign the row(“ColumnName”) to the variables and perform action needed, you can check the value for that and have condition in there
Also, suggest you to debug first and add a breakpoint after reading the Datatable. you will see in Local the Datatable loaded, that view would give you some hint to proceed.
Again, sharing the file or screenshot would help us to help you.
Here’s the screenshot (data are fake, so don’t worry about the names). Dont take into account Column B for now. So basically what I want to automate is " filling a row for each company that has a different name". For example, the output for “Unit&Products Inc” in the first row would be:
under ClientName → Unit&Products Inc
under Invoice ID → the total number of invoices related to Unit&Products Inc
under Invoice Value → the sum of all the invoices that are related to Unit&Products Inc
In this manner instead of having 7 Rows related to “Unit&Products Inc” where each represent an invoice, I’d have 1 row representing the whole situation of “Unit&Products inc”.
In the 2nd Row I would have the same for “Travels Print”, in the 3rd for “Teamatix” and so on.
Hope this can help understanding!
Thank you in advance @rahulsharma
Read the excel and store in dt1 (datatable variable)
Create a datatable with build datatable activity with required headers u need in final excel (company name, total number of invoices, total values of invoices) and store in dt_final
Now use for each row to loop through each row under dt1.DefaultView.ToTable(True,“Column A”)
Now inside the loop do the following things
Filter the dt1 with row(“Column A”) and store in dt2 variable.
Now use a assign activity to add the following things
model the 3 cols: ClientName, InvoiceCount, Sum (feel free on col names) -
output/Variable: dtResult
Use an assign acitvity
Left side: dtResult
Right side
(From d in YourDataTableVar.AsEnumerable
Group d by k=d("ClientName").toString.Trim into grp=Group
Let s = grp.Sum(Function (x) CInt(d("InvoiceValue").toString.Trim))
Let ra = new Object(){k, grp.Count, s}
Select r=dtResult.Rows.Add(ra)).CopyToDataTable
with these two steps you will create the report as specified above. Feel free to read more about Grouping Data and LINQ here:
I see. As I said I am very very new and don’t understand a lot about it , I am trying to learn and I ended up having errors.
First of all, to let you better understand (maybe here’s the mistake I made) the screenshot I sent was of an excel file (called “Risultati” ) which was the output of doing a “write range” activity. Since I wanted to follow @NIVED_NAMBIAR plan I started from the DataTable stored in Uipath (deleting the write range activity) with the same values shown in the screenshot. After that I just followed said plan. Despite being clear, I don’t know what to put as “operation” (and the following value) in the configure filter ( step 3 part 1). Furthermore when using “assign activity” for Total_value_invoices I received this error : cannot assign from type ‘System.Double’ to type ‘System.String’ in assign activity ‘Assign’
I lack programming skills probably and that’s why I am having many issues. I am following the advanced plan to take the certificate. If you have any tips also just send them my away, I’ll gladly take them.
Thank you in advance,
Alessandro
I am almost there. The only problem is that it doesnt actually calculate the total number of Invoices (Column B) and the total value of the invoices (Column C) for each company but rather the total of all of them. 26 in fact is the sum of the of invoices of all the companies.
here’s the xaml Main.xaml (18.0 KB)
Thank you @ppr and @NIVED_NAMBIAR It worked out Finally! I think I’ll train myself also with the solution that you Peter gave me with the group. I have one more question though related to this formula:
“r” is arbitrary ? I could have chosen s or x without any issue whatsoever, right?