Hello, I have a project where I need to sort a list in Excel (several negative values to several positives). I have sorted it but I now need to run a =SUM function on all negative cells and all positive values to get two separate totals that I will then read/write into another excel. Can anyone offer help with this? I have been trying to use an IF activity but cant seem to get it.

Welcome to the community

You can use sum if in excel

`=SUMIF(B2:B25,">0")`

Change the range as you need

Cheers

I apologize if this is a dumb question, What activity in StudioX would be able to have the SumIf function?

Sumif is a excel formula…you can use write cell to write the formula on to excel and it would show the sum yhere

If you need it in variable in studiox then you can simply follow below steps

- For each row in excel
- If condition to check if value is
`cint(currentrow("column").ToString)>.0`

- On left use
`posiytivesum = positivesum+ cint(currentrow("column").ToString)`

Similarly on else side use for negativesum

Negativesum and positivesum are integer type variables

Cheers

1 Like

Hi,

The following sample may help you.

```
positiveSum = dt.AsEnumerable.Where(Function(r) cdec(r("value").ToString)>0).Sum(Function(r) cdec(r("value").ToString))
negativeSum = dt.AsEnumerable.Where(Function(r) cdec(r("value").ToString)<0).Sum(Function(r) cdec(r("value").ToString))
```

Sample

NewBlankTask20240731.zip (57.2 KB)

Regards,