coder
(coder)
June 16, 2023, 5:44am
1
Hi,
How I can group the column of the contract and get the count of the Status?
for example:
> ContactNumber Status
>
> Contract 1 Submitted
>
> Contract 2 Not-Submitted
>
> Contract 4 Submitted
>
> Contract 2 Not-Submitted
>
> Contract 1 None
Output:
ContactNumber Total Submitted Not-Submitted
Contract 1
Contract 2
Contract 3
Thank you
Srini84
(Srinivas Kadamati)
June 16, 2023, 6:10am
2
@coder
First use Build Datatable activity and declare your required Output Columns which are ContactNumber, Total, Submitted, Not-Submitted Let’s call this as dt_withoutData
Data as below
Then use your datatable with the results and let’s call this as dt_withData
Now use Assign activity dt_withoutData = and write below LinQ expression
Then your results in dt_withoutData is like below
Hope this may help you
Thanks,
Srini
Yoichi
(Yoichi)
June 16, 2023, 6:13am
3
Hi,
Can you try the following sample?
dtResult = dt.AsEnumerable.GroupBy(Function(r) r("ContractNumber").ToString).Select(Function(g) dtResult.LoadDataRow({g.Key,g.Count,g.Where(Function(r) r("Status").ToString="Submitted").Count,g.Where(Function(r) r("Status").ToString="Not-Submitted").Count},False)).CopyToDataTable
Sample20230616-6L.zip (9.0 KB)
Regards,
coder
(coder)
June 16, 2023, 6:30am
4
thank you, can you please copy the code for assign, I get some errors.
coder
(coder)
June 16, 2023, 6:32am
5
Thank you for your help.
but I want the total to be 1, not 2. like the total for values that are in this table only.
Thank you
Srini84
(Srinivas Kadamati)
June 16, 2023, 6:33am
6
@coder
Here is the code for your reference
Excel_Process.zip (8.7 KB)
Thanks,
Srini
1 Like
Yoichi
(Yoichi)
June 16, 2023, 6:36am
7
Hi,
How about the following?
dt = dt.AsEnumerable.GroupBy(Function(r) r("ContractNumber").ToString).Select(Function(g) dtResult.LoadDataRow({g.Key,g.Where(Function(r) r("Status").ToString="Not-Submitted" OrElse r("Status").ToString="Submitted" ).Count,g.Where(Function(r) r("Status").ToString="Submitted").Count,g.Where(Function(r) r("Status").ToString="Not-Submitted").Count},False)).CopyToDataTable
Sample20230616-6Lv2.zip (9.1 KB)
Regards,
1 Like
coder
(coder)
June 16, 2023, 7:09am
8
Thank you, it’s working, can we also please add another column for percentages?
Number of Submitted/ total
Thank you
Yoichi
(Yoichi)
June 16, 2023, 7:20am
10
Hi,
Can you try the following sample?
Sample20230616-6Lv3.zip (9.1 KB)
Regards,
1 Like
coder
(coder)
June 16, 2023, 7:39am
11
Thank you for your help, sorry to distribute you. but I have one last question, can we also add the total at the end of each column with another row for percentages?
like this:
Status/ Total * 100
Thank you
Yoichi
(Yoichi)
June 16, 2023, 8:09am
12
Hope this helps you.
Sample20230616-6Lv4.zip (9.3 KB)
1 Like
coder
(coder)
June 16, 2023, 8:47am
13
Thank you so much,
its is possible to add the ContractNumber in the Template also like the Status?
so if the ContractNumber is not available in the column then we will write 0 or put the cell empty.
like this
Thank you
Yoichi
(Yoichi)
June 16, 2023, 9:00am
14
HI,
Can you check the following?
Sample20230616-6Lv5.zip (9.7 KB)
Regards,
1 Like
coder
(coder)
June 16, 2023, 9:30am
15
Thank you for your help.
but also I want to add the percentage here. its last thing
Thank you
Yoichi
(Yoichi)
June 16, 2023, 9:34am
16
Hi,
What value? Is it 100%? if so please use the following expression in AddDaaRow activity
If not, please modify the following last “100%” part into what you need.
{"%","",(100*dtResult.AsEnumerable.Select(Function(r) CInt(r(2))).Take(dtResult.Rows.Count-1).Sum/CInt(dtResult.Rows(dtResult.Rows.Count-1)(1))).ToString+"%", (100*dtResult.AsEnumerable.Select(Function(r) CInt(r(3))).Take(dtResult.Rows.Count-1).Sum/CInt(dtResult.Rows(dtResult.Rows.Count-1)(1))).ToString+"%","100%"}
2 Likes
coder
(coder)
June 16, 2023, 10:48am
17
Thank you for your help. its working
coder
(coder)
June 16, 2023, 10:58am
18
can you please explain to me these codes:
dtResult.AsEnumerable.Select(Function(r) r(0).ToString).ToArray()
And then why do you Clear Data Table?
arrContractNumber.Except(dtresult.AsEnumerable.Select(Function(r) r(0).ToString))
{“total”}.Concat(dtResult.Columns.Cast(Of DataColumn).Skip(1).Take(3).Select(Function(dc) dtResult.AsEnumerable.Sum(Function(r) CInt(r(dc))).toString)).ToArray()
{“%”,“”,(100dtResult.AsEnumerable.Select(Function(r) CInt(r(2))).Take(dtResult.Rows.Count-1).Sum/CInt(dtResult.Rows(dtResult.Rows.Count-1)(1))).ToString+“%”, (100 dtResult.AsEnumerable.Select(Function(r) CInt(r(3))).Take(dtResult.Rows.Count-1).Sum/CInt(dtResult.Rows(dtResult.Rows.Count-1)(1))).ToString+“%”,“100%”}
Thank you
Yoichi
(Yoichi)
June 16, 2023, 2:15pm
19
The above expression returns data in column 0 as string array. It’s necessary to identify which contract number exists or not.
As the following logic appends grouping row, existing rows is unnecessary.
arrContractNumber.Except(dtresult.AsEnumerable.Select(Function(r) r(0).ToString))
This expression extract contractnumber which doesn’t exists in the datatable.
{“total”}.Concat(dtResult.Columns.Cast(Of DataColumn).Skip(1).Take(3).Select(Function(dc) dtResult.AsEnumerable.Sum(Function(r) CInt(r(dc))).toString)).ToArray()
This expression is additional row for total. The 1st item is “total” and calculate sum in each 2nd,3rd and 4th column.
{“%”,“”,(100dtResult.AsEnumerable.Select(Function(r) CInt(r(2))).Take(dtResult.Rows.Count-1).Sum/CInt(dtResult.Rows(dtResult.Rows.Count-1)(1))).ToString+“%”, (100 dtResult.AsEnumerable.Select(Function(r) CInt(r(3))).Take(dtResult.Rows.Count-1).Sum/CInt(dtResult.Rows(dtResult.Rows.Count-1)(1))).ToString+“%”,“100%”}
This expression is additional row for percentage.The 1st item is “%”. The 2nd item is “”. 3rd and 4th
item is result of calculate percentage. 5th is “100%”
Regards,
2 Likes
coder
(coder)
June 18, 2023, 9:19am
21
Thank you a lot for your help.
system
(system)
Closed
June 22, 2023, 1:36pm
23
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.