How to get a value between a given range

I have scraped this a website, where Im taking out the “Land” and “Area in km2”, and write it to a datatable.

Then I’m going to get the “Land” that have an “Area in km2” between 300 000 km2 and 400 000 km2. But I got more than I wanted (see picture).

I think is the numbers in Excel is String and not Integer or something.

2 Likes

Fine
Kindly try with this expression
—hope we have the datatable ready named dt
So in the assign activity the expression to be used is
dt = dt.Select(“[Areal] >= ‘300000’ AND [Areal] <= ‘400000’ “ ).CopyToDatatable()

This will give you the records between that range

Cheers @Mariafig

1 Like

Great! I will try this :slight_smile: And I will si if this works when the range is dynamic. The user is going to type this in :+1:

1 Like

Yah if the range is dynamic then we can mention the variable in this expression so that the variable can be passed with dynamic values
Like this
dt = dt.Select(“[Areal] <= ‘ “ + firstrange.ToString + “ ’ AND [Areal] >= ‘ “ + secondrange.ToString + “ ’ “ ).CopyToDatatable()

Cheers @Mariafig

1 Like

I got this error message, see picture.
image

Her is my test xaml: HentUt_Areal – Kopi.xaml (15.8 KB)

1 Like

Aaha
I miss placed the operators
I changed in the previous comment
The expression would be like this
dt = dt.Select(“[Areal] >= ‘300000’ AND [Areal] <= ‘400000’ “ ).CopyToDatatable()

Cheers @Mariafig

1 Like

Hmm I get the same error message.

“ArealFra” is from input dialog with value 300000
“ArealTil” is from input dialog with value 400000

I will get the values between this range.

1 Like

Still you haven’t changed the expression buddy
Sorry that was my fault
This is the expression
dt = dt.Select(“[Areal] >= ‘300000’ AND [Areal] <= ‘400000’ “ ).CopyToDatatable()

Cheers @Mariafig

1 Like

I tried it now, got this.
image

Her is my expression:

Have you kept any space between > and =
There should be no space
Kindly re type it please
Cheers @Mariafig

1 Like

Thanks :slight_smile:

Im sorry, but now I got a new error message:laughing:
image


1 Like

No worries buddy
There should be no space between > = it should be like >= and similarly for <= applies same. it should not be like < =
Where in the expression you could be able to see the red curved line next to [Areal] in the beginning of the expression. that implies the same

As there is space between the operators > and = and also in < and = we are getting the error
Mention without any space
Like

=
<=

and kindly dont copy this and paste, that might errorout sometimes, type this expression with the field @Mariafig

Cheers

1 Like

It seems the Areal column format is not numeric. You may have to remove the spaces before applying a filter. Use any method to remove spaces (For Each loop on the datatable and replacing spaces with null is an option). Once the spaces are removed you can apply the filter.

1 Like

But the error depicts the exception clearly that Missing Operands and in the screenshot this
There is a red curly line next to Selectt(“ [Areal]
image https://global.discourse-cdn.com/uipath/optimized/3X/8/1/81995327460b837c7a75ec9364b75616b827b9d1_2_690x209.png

I hope we need to check with the expression
Cheers @Mariafig

1 Like

Hi,

Perhaps you should convert cell value to numeric (as mentioned @midhunsug661 ) and compare as Int32 because string comparition differ from numeric comparition. For example “4000” is larger than “300000” by string comparition.

So can you try the following?

dt=dt.AsEnumerable.Where(function(r) CInt(r("Areal").ToString.Replace(" ",""))>=300000 And CInt(r("Areal").ToString.Replace(" ",""))<=400000).CopyToDataTable

Regards,

3 Likes

@Mariafig @Palaniyappan The reason why the error comes in the box is because you have copied the syntax from the forum. Just write the double quotes manually from the keyboard and the issue will be solved.

1 Like

@Yoichi @midhunsug661 Thank you, and think I understand this, but Im still very confused :stuck_out_tongue:

Is it possible for you to see at mye workflow?
HentUt_Areal.xaml (19.0 KB)
NasjonalInfo.xlsx (19.6 KB)

Hi @Mariafig

Before that Areal column remove the spaces by row(“Areal”).ToString.Trim

Use Dt.Select(“[Areal]>='400000 and [Areal]<=‘300000’”).CopyToDatatable()

Thanks
Ashwin S

1 Like

Hi,

Please try the following condition in the if activity, because string comparition differ from numeric comparition.

CInt(row.Item("Areal").ToString.Replace(" ", "")) >= CInt(ArealFra) and CInt(row.Item("Areal").ToString.Replace(" ", "")) <= CInt(ArealTil)

Regards,

3 Likes

Omg, it worked :smiley: :smiley: :smiley: :smiley: Now Im so happy!

Thank thank thank you very mutch!!! Now I will test it out with different rang intervals!

And thank you to you all that have helped me @Palaniyappan @Yoichi @AshwinS2 @midhunsug661 :slight_smile:

4 Likes