Counting while..

11 posts / 0 new
Last post
noamh
Offline
Joined: 06/26/2017 - 07:45
Counting while..

hi all,
new to idea scripting..
how can i create field that counts while somthing happans in other field?
foe example:
in every row, as long as Employee Number is the same, keep counting 1...2...3...4...
and when the number changes to another Employee, start all over again 1..2..3...

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi noamh and welcome to the site.

Actually this is one that I get asked fairly often so I have put together a script to do this. You can find it here: http://ideascripting.com/ideascript/add-counting-column

Let me know if you have any comments or problems using it.

Thanks

Brian

noamh
Offline
Joined: 06/26/2017 - 07:45

Tnank You Brain!
when i try the script, i does not quiet work.. as you see the image, the "counting" doesn'nt count and i would like it to start counting every time there is a change in the field (even if the data repeat itself every couple of rows. for the first "1-1" it suppose to be 1,2,3 and for second "1-1" starts again 1,2 .
in the middle, the "1-0" would just give me a solid 1 counting..
 

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi noamh,

That is interesting.  I created a test file that was similar to yours:

I ran the script.

Thisis what I got.

Now one thing I forgot to add to the script is you need to close the file and reopen it to view the count field properly.

I just noticed something, are you running this on a virtual field?  If so can you recreate the field as an IDEA field, so when creating the field select Character instead of virtual Character.  The problem is virtual character fields stores the formula and not the results but we want to do this on the results.  I will update the script to add a warning about that or maybe to filter out virtual fields.

Thanks

Brian

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

I added some code to exclude virtual fields from being selected and added a warning to the dialog. 

noamh
Offline
Joined: 06/26/2017 - 07:45

Do you have any suggestions how to change virtual character to  character?
the content that i tried to put in this field is :
@alltrim(@str(Emp,20,0))+"-"+@alltrim(@str(DAYS_STRAIGHT1,20,0))
 
 

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Noamh,

First you create the IDEA Character Field using the Field Manipulation.  The field length should be the same as the virtual file.

Then click on parameter and just enter in the field you want to copy, in my case the virtual field.

click on validate and exit and then exit and you should have your new field.

Let me know how this goes.

Brian

 

noamh
Offline
Joined: 06/26/2017 - 07:45

still not working..
did exactly as shown and got the same error.
attached the picture (don't mind the hebrew fonts, tried to change them to english and didn't work neither)

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi noamh,

This is strange.  Any chance you can share with me the parts of the file, such as the two fields that create your virtual field so I can try and understand what is going on.  I am wondering if it is a problem between my ASCII version and your Unicode version.  The problem is the script seems to work fine for me. 

If you want to share it you can email me at brian.element@ideascripting.com.

Thanks

Brian

noamh
Offline
Joined: 06/26/2017 - 07:45

i emaild you :)

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Thanks, I will look at it tonight.