Find the closest value in Data row


I am looking to find the closest value in the data row.

See for below example.


I need to find out the closest value(rounded up value) in row 2 and target value - 31.1

Would be great if you could give me suggestions

1 Like

Buddy you can get like this @kavinnatarajan

iterate through each value in a foreach row loop by passing this as a datatable read from a excel with read range inside excel application scope
–then inside the for each row loop use a assign activity like this buddy
out_value = (Convert.ToDouble(row(0).ToString)+Convert.ToDouble(row(1).ToString)+Convert.ToDouble(row(2).ToString).Convert.ToDouble(row(3).ToString))/4

or directly from second row like this buddy @kavinnatarajan
out_value = (Convert.ToDouble(outdt.Rows(1)(0).ToString)+Convert.ToDouble(outdt.Rows(1)(1).ToString)+Convert.ToDouble(outdt.Rows(1)(2).ToString).Convert.ToDouble(outdt.Rows(1)(3).ToString))/4

where outdt is the datatable you have
where out value is of type double
then you can get the value with closest value like this buddy in a writeline activity or a assign activity

Thats all buddy you are done
Try this and let know buddy whether this works or not
Kindly correct me if i have understood the query wrongly @kavinnatarajan

Buddy thanks for you reply.

But Im looking to find the nearest value of my targetNumber 31.1 in row 2.

For example nearest value of 31.1 in row 2 would be 32.40 (rounded up)

Any idea?

Hi there, @Palaniyappan I think s/he is asking how to build the logic based on closest value to an input value of 31.1.

meaning from the row two the closest to 31.1 is 30.5, so for any given input value the bot should calculate the closest number that is present in the row or array (or atleast that’s what I understand from her question - it could have been much clearer with input and output with an example)

@kavinnatarajan what you are asking is basically logical, so maybe I can build a test.xaml for that.

Exactly …Thanks a lot… :slight_smile:

Well here you go…!

You can build a bigger data table and compare values and store them in any kind of collection to be appended to array or data table to be written in any kind of output.

File : Main.xaml (11.5 KB)

I guess this is it. Please close this topic marking the solution

Regards :slight_smile:

That’s Great … Could u please explain it

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