Sum of select item of excel

Hello I have a problem.
I have two columns in excel one is called value and the other concept, I filter concept and I need to add the related data in the value column that corresponds to this concept, how can I do so that only I add the value corresponding to this concept?

@Beatriz_Eugenia_Duqu

  • Read your workbook with ReadRange activity and obtain a DataTable (dt below)
  • Apply a Select to the DataTable and chain a Sum to it. Below, searched concept is "A".

I also assume that you’re adding Integers. Adapt the type conversion and types to suit your needs

Variables

dt As DataTable
concept As String
filter As String
conceptSum As Int32

Assigns

concept = "A"
filter = String.Format("concept='{0}'", concept)
conceptSum = dt.Select(filter).Sum(Function(row) CInt(row("value")))

One-liner version

dt.Select("concept='A'").Sum(Function(row) CInt(row("value")))

3 Likes

It’s great thanks

This worked for me correctly

How can I multiply that same data by -1?

@Beatriz_Eugenia_Duqu

I probably don’t get your question right. All the expressions below are equal.

(-1 * A) + (-1 * B) + (-1 * C)
(-A) + (-B) + (-C)
-(A + B + C)
(-1) * (A + B + C)

I must multiply these same values ​​before adding them by -1

Well, this is just like multiplying the sum by -1.

dt.Select("concept='A'").Sum(Function(row) CInt(row("value"))) * -1

or

dt.Select("concept='A'").Sum(Function(row) CInt(row("value")) * -1)

1 Like

It does not work, since I must multiply each concept by -1 before doing the sum, so this function what it does is that the sum of the full value is multiplied by -1

Can you please show me an example?

I need to do basically the same thing as the addition function but multiplying by -1

It’s Ok

How can I limit the added value to remain as a single value in the variable since when I use the variable the number of times that the concept traversed in the datatable is repeated to me?

Hello @Beatriz_Eugenia_Duqu

A GROUPBY with aggregation? A similar question was asked a week ago.

Thanks
Your help was very valuable, I already managed to do the process

1 Like