Calculate distance between two points (numbers) in a number line

S

Silvio

Hello everyone, how can I calculate the distance between two points (numbers)
in a number line using a calculated field? For example: (Filed1 and Filed are
saved number in any combination of positive and negative numbers)

Filed1 = -10
Field2 = +15
Number distance = 25 (this is the correct result)

Example 2:
Filed1 = -10
Field2 = -5
Distance = 5 (this is the correct result)

Example 3:
Filed1 = -10
Field2 = 5
Distance = 15 (this is the correct result)

This is what I have done but it does not work with combination of negative
and positive numbers...

=(IIf(([Filed1]>[Filed2]),Abs([Filed1])-Abs([Filed2]),([Filed2]-[Filed1])))
 
T

Tom Lake

Silvio said:
Hello everyone, how can I calculate the distance between two points
(numbers)
in a number line using a calculated field? For example: (Filed1 and Filed
are
saved number in any combination of positive and negative numbers)

Filed1 = -10
Field2 = +15
Number distance = 25 (this is the correct result)

Example 2:
Filed1 = -10
Field2 = -5
Distance = 5 (this is the correct result)

Example 3:
Filed1 = -10
Field2 = 5
Distance = 15 (this is the correct result)

This is what I have done but it does not work with combination of negative
and positive numbers...

=(IIf(([Filed1]>[Filed2]),Abs([Filed1])-Abs([Filed2]),([Filed2]-[Filed1])))

Why not just do

=Abs([Filed1] - [Filed2])

(did you mean Field1 and Field2?)

Tom Lake
 
S

Silvio

Thanks Tom, easy enough. I hope this is just my *Monday* brain breakdown.
(Yes I ment Field1 and Field2).

Tom Lake said:
Silvio said:
Hello everyone, how can I calculate the distance between two points
(numbers)
in a number line using a calculated field? For example: (Filed1 and Filed
are
saved number in any combination of positive and negative numbers)

Filed1 = -10
Field2 = +15
Number distance = 25 (this is the correct result)

Example 2:
Filed1 = -10
Field2 = -5
Distance = 5 (this is the correct result)

Example 3:
Filed1 = -10
Field2 = 5
Distance = 15 (this is the correct result)

This is what I have done but it does not work with combination of negative
and positive numbers...

=(IIf(([Filed1]>[Filed2]),Abs([Filed1])-Abs([Filed2]),([Filed2]-[Filed1])))

Why not just do

=Abs([Filed1] - [Filed2])

(did you mean Field1 and Field2?)

Tom Lake
 
D

Damon Heron

=IIf(([filed1]<0 And [filed2]<0) Or ([filed1]>0 And
[filed2]>0),([filed1]-[filed2]),(Abs([filed1])+Abs(([filed2]))))

Thats provided filed1 (field1??) or filed2 are not = 0.

Damon
 
D

Damon Heron

I just had one of those DUH moments - Tom Lake gave me a wake-up call.

Damon

Damon Heron said:
=IIf(([filed1]<0 And [filed2]<0) Or ([filed1]>0 And
[filed2]>0),([filed1]-[filed2]),(Abs([filed1])+Abs(([filed2]))))

Thats provided filed1 (field1??) or filed2 are not = 0.

Damon

Silvio said:
Hello everyone, how can I calculate the distance between two points
(numbers)
in a number line using a calculated field? For example: (Filed1 and Filed
are
saved number in any combination of positive and negative numbers)

Filed1 = -10
Field2 = +15
Number distance = 25 (this is the correct result)

Example 2:
Filed1 = -10
Field2 = -5
Distance = 5 (this is the correct result)

Example 3:
Filed1 = -10
Field2 = 5
Distance = 15 (this is the correct result)

This is what I have done but it does not work with combination of
negative
and positive numbers...

=(IIf(([Filed1]>[Filed2]),Abs([Filed1])-Abs([Filed2]),([Filed2]-[Filed1])))
 
S

Silvio

I am glad to see that I am not the only one :)

Damon Heron said:
I just had one of those DUH moments - Tom Lake gave me a wake-up call.

Damon

Damon Heron said:
=IIf(([filed1]<0 And [filed2]<0) Or ([filed1]>0 And
[filed2]>0),([filed1]-[filed2]),(Abs([filed1])+Abs(([filed2]))))

Thats provided filed1 (field1??) or filed2 are not = 0.

Damon

Silvio said:
Hello everyone, how can I calculate the distance between two points
(numbers)
in a number line using a calculated field? For example: (Filed1 and Filed
are
saved number in any combination of positive and negative numbers)

Filed1 = -10
Field2 = +15
Number distance = 25 (this is the correct result)

Example 2:
Filed1 = -10
Field2 = -5
Distance = 5 (this is the correct result)

Example 3:
Filed1 = -10
Field2 = 5
Distance = 15 (this is the correct result)

This is what I have done but it does not work with combination of
negative
and positive numbers...

=(IIf(([Filed1]>[Filed2]),Abs([Filed1])-Abs([Filed2]),([Filed2]-[Filed1])))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top