Jump to content

Calculation adding 1 to field value


This topic is 5689 days old. Please don't post here. Open a new topic instead.

Recommended Posts

This seems trivial, but...

I am having a little difficulty with a script that is intended to examine the contents of a field, and if it is "A", add 1 to a field in a related record, if it is "B", add 1 to another field in a related record, etc..

Basically I am making a counter script to record the number of times a particular value occurs in a field, that I can run on a found subset of my main table. However, I am having a little trouble creating the calculation. Does anyone know how to do this?

Marcel

Link to comment
Share on other sites

... You could just use a summary field to do this and sub summarize by your letter field to get you a count.

But if you are desperate to use the script for whatever reason..

If[Field = "A"]

Set Field[RelatedField::A ; 1 ]

Else If[Field = "B"]

Set Field[RelatedField:: ; 1 ]

...

Else If[Field = "Z"]

Set Field[RelatedField::Z ; 1 ]

End If

Link to comment
Share on other sites

Hi thanks,

Sorry should have been more clear; I am actually trying to mathematically increment the present value of the related field by 1 (ie if the present value in the related field is 6 and the conditions are met, the value after the script step would be 7).

I am not desperate to use a script, and if there is an easier way, by all means.. I am not sure how to create a summary field to do what I am hoping to do. I did look up summary fields, but it is not clear to me how I can use them to calculate sums on a found subset of records in the main table.

M

Edited by Guest
Link to comment
Share on other sites

If the calculation field was a different field than B, you could use a calculation:

NewField (Calculation, Number) =

Case ( A::A = "Zee" ; B + 1 )

However, in order to change the same field, you would have to use a Script.

If [ A::A = "Zee" ]

Set Field [ Related::; Related:: + 1 ]

End If

HTH

Lee

Link to comment
Share on other sites

Yes, I am hoping to use this for reporting.

OK so I tried inserting the calculation

If [ A::A = "Zee" ]

Set Field [ Related::; Related:: + 1 ]

End If

into the script, and this morning for some reason it works just fine. Thanks for the help!

M

Link to comment
Share on other sites

Marcel--

Running a script through every record just to count values is a slow way to solve the problem--especially as the file grows.

Look at what Genx first said: You can accomplish what you want--without a script--by creating a report that uses a summary field and then breaking on the field's value.

Now, if you need to track (for documentational purposes) the values over time, you could still use a relational approach to capture these values by creating a global field to work in conjunction with your summary field. Build a relationship between the global field and the field, set your summary to count through that relationship, and then loop through the field values in your script. The summary field would give you a total for each value without having to read every record in the table, and you could store that. I suspect it would go much faster this way.

HTH,

David

Link to comment
Share on other sites

This topic is 5689 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.