Iterate through a column until a specific value appears

How to iterate through a column to fetch the data till a specific value appears .

excelvalues

for example : I would like to sum the values until the month of Feb (months are passed as argument depend on the user needs )

for now i have created a DT with all values from the excel
then tried to filter the DT but no option to specify

Variable (String)
Sentinel= “Feb”

Variable (Int32)
Result = 0

ForEachRow in DT:

  • Assign
    Result = Result + Cint(row(“values”))

  • If
    row(“Month”).ToString = Sentinel:

    • Break

LogMessage
Result.ToString

2 Likes

@FMK
as an alternate it can be done with using Take() and Sum()

dtData.AsEnumerable.Take(idx +1).Sum(Function ® CInt(r(1).toString))

Find Demo XAML here
FMK.xaml (7.8 KB)

4 Likes

thank you all , both solutions worked

I also have a question how can i get the values of the monthes after Feb till current month excelvalues

for example i need each value of March and April

can you help me on that

@FMK
Find a starter help here:
FMK2.xaml (9.8 KB)

1 Like

Thank you it worked

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