In the table that I will get this variable, column names go up to F1, F2, F2 … F12. There are also columns that named B1, B2, B3 … B12.
The variable I’m going to write should get data from the B columns of the previous month’s number.
For example, if we are in the 5th month, he should take columns B4. Then i will do the same thing for the columns F.
For the other variable;
It should take the sum of all the columns from the 1st month to the previous month. For example, if we are in the 5th month, the variable should be B1+B2+B3+B4.
Once after getting the datatable variable from excel with read range activity use a FOR EACH ROW activity and pass the above variable as input let’s say like dt
—now use a assign activity inside the for each loop like this str_columnname = “B”+If(Now. AddMonths(-1)ToString(“mm”).Startswith(“0”),Now. AddMonths(-1).ToString(“mm”).Replace(“0”),Now. AddMonths(-1).ToString(“mm”))
Now next to this use a assign activity like this str_output = row(str_columnname).ToString
This will give the B column numbers value and similarly for F columns as well
And for the next scenario
—next to the above assign activity use another assign activity like this Int_colindex = dt.Columns.IndexOf(“B”+If(Now. AddMonths(-1)ToString(“mm”).Startswith(“0”),Now. AddMonths(-1).ToString(“mm”).Replace(“0”),Now. AddMonths(-1).ToString(“mm”)))
Same inside the for each row loop use a While loop Like this counter < int_colindex
Where counter is a variable of type int32 with default value as 1 defined in the variable panel
—Inside this while loop use a assign activity like this int_sum = Convert.ToUnt32(row(counter))+ int_sum
Where int_sum is a int32 variable defined in the variable panel with default value as 0
Thanks a lot buddy. i think it will work but now there is a problem. When i trying to first step; i have seen this error :
“overload resolution failed because no accessible ‘replace’ accepts this number of arguments”
You should try this
use assign activity in for each:
“B”+System.DateTime.Now.AddMonths(-1).ToString(“MM”): it will give you previous month column. for 1st variable.
now for second problem:
now we will use while loop in for each loop counter will start from 1 to convert.toInt32(System.DateTime.Now.AddMonths(-1)ToString(“MM”)).
In while loop:
use assign activity:
variable2=variable2+row.column(“B”+counter)
when the datatable has no such column under that name then the index value will be -1
thats why
and in the while loop include this condition so that we wont face issue with that as well int_colindex > 0 and counter < int_colindex