Index was outside the bounds of the array with Linq Codes

Hi!

I need some help for Linq Code ; I want to do that mutible group by sum of column. So I have three columns and 10.000+ rows. I must group same rows and sum. I have below Linq codes;

GnlEnumDT => (From M In DT.AsEnumerable()
Group M By M_No = New With { key.MusteriNo = M.item(0), key.MusteriAdi = M.item(1) }
Into MGroup = Group Select New With { M_No.MusteriNo, M_No.MusteriAdi, .Toplam=MGroup.Sum(Function( x ) Double.Parse((x.Item(2).ToString.Replace(".","")).ToString.Replace(",",".")))}).toList

and

StrResult_=> String.Join(",",GenelIEFormulGelen(0).ToString.Split(",“c).Select(Function(item) item.ToString.Split(”=“c)(0).Replace(”{","").Trim))+System.Environment.NewLine+
String.Join(System.Environment.NewLine,GenelIEFormulGelen.Select(Function(row) String.Join(",",row.ToString.Split(",“c).Select(Function(item) item.ToString.Split(”=“c)(1).Replace(”}","").Trim.ToString))))

When I try it I am gettin an error at StrResult_ assign. “Assign: Index was outside the bounds of the array.” How can I run it within array boundaries. do you have any idea?

Thanks!

Happy Automation!

Hello @mhmmtsdkmrt!

It seems that you have trouble getting an answer to your question in the first 24 hours.
Let us give you a few hints and helpful links.

First, make sure you browsed through our Forum FAQ Beginner’s Guide. It will teach you what should be included in your topic.

You can check out some of our resources directly, see below:

  1. Always search first. It is the best way to quickly find your answer. Check out the image icon for that.
    Clicking the options button will let you set more specific topic search filters, i.e. only the ones with a solution.

  2. Topic that contains most common solutions with example project files can be found here.

  3. Read our official documentation where you can find a lot of information and instructions about each of our products:

  4. Watch the videos on our official YouTube channel for more visual tutorials.

  5. Meet us and our users on our Community Slack and ask your question there.

Hopefully this will let you easily find the solution/information you need. Once you have it, we would be happy if you could share your findings here and mark it as a solution. This will help other users find it in the future.

Thank you for helping us build our UiPath Community!

Cheers from your friendly
Forum_Staff

Hi @mhmmtsdkmrt,
Sorry for general answer but I don’t exactly have idea what you are trying to do with these Linq queries. Usually outside boundaries errors occurs when during looping though all elements in array you will go to far. Please remember that indexing is always starting from 0 not from 1. So maybe adding somewhere in your query a “-1” will help? Just guessing.

1 Like

Thank you for your response Pawel! I think I solved but used different a route.

1 Like

Great! Please let us know what was the solution which helped you. It could help in case someone will have similar issue :slight_smile:

Of course Dear Pawel. Actually I used different a LinQ Codes for my new solution but I think there is error because of header for my old codes. Anyway…

As I say, I have a data table. it has three colums and 10.000+ rows. I needed group same rows and sum on this data table.

Firtsly,
My DataTable name is FirstGeneralDT and I used a list. List name is ListA (string of List)

GeneralDT = (From M In FirstGeneralDT.Select() Group M by MusteriNo=M.Item(“Column1”).ToString into Group Select Group(0)).toArray.Copytodatatable()

GeneralDT = FirstGeneralDT.DefaultView.ToTable(False,“Column1”,“Column2”,“Column3”)

ListA = (From M In FirstGeneralDT.Select()
Group M By MusteriNo=M.Item(“Column1”).ToString, MusteriAdi=M.Item(“Column2”).ToString Into GroupA=Group
Select Convert.ToString(GroupA.Sum(Function(x) Double.Parse(x.Item(“Column3”).ToString.Replace(".","").Replace(",","."))))).ToList()

For Each row in FirstGeneralDT

row(“Column3”) = ListA(GeneralDT.Rows.IndexOf(row)).ToString

and

I wrote this Data Table with write Range than I continue to happy automations :slight_smile:

I hope this solution will be helpful to others.

Happy Automation!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.