Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
124rooski
Partner - Creator
Partner - Creator

Looking to auto increment the next row value without user input

Hi all - 

As the title explains, I am looking for a way to auto increment the new row value with the previous row value.

I've got a dimension (MOVIE_VIDEO_NUMBER) that already has data - 1, 2, 3, 4, 5, 6 and 7.

The idea is when a user adds a new row of data (using vizlibs writeback table) I want to auto generate by taking the previous MOVIE_VIDEO_NUMBER and adding 1 to it. Taking my example above, the next row of data created would automatically have an 8, the next would be 9, and so forth.

I've tried playing with the peek and previous function but not grabbing the value I want. I'm sure there is a simpler method and wanted to reach out here. 

Thanks.

Labels (1)
2 Replies
JordyWegman
Partner - Master
Partner - Master

Hi Rooski,

Nice that you are working with the Vizlib Writeback. I think working with Previous() is the way to go.

Writeback give you a timestamp for the entered value. So you script should be something like this:

WritebackTable:
Load
    *, // all your data, but can't be a star because you are using the same [YourIncrementField] field
    IF( Trim( [YourIncrementField] ) & '' = '',
        Peek( Previous( [YourIncrementField] ) ) + 1,
        [YourIncrementField]
    )                                            as [YourIncrementField]
Resident [YourSource]
Order by [WriteBackTimeStamp] asc
;

 

Peek() & Previous() can sometimes give you some headaches, but fits your solution.

Jordy

Climber

Work smarter, not harder
124rooski
Partner - Creator
Partner - Creator
Author

Hey JordyWegman thanks for dropping in. I am assuming this script would go under the first script of the injected writeback provided by the wizard? This would be before the load where vizlib converts all of your fields into varchar since it converts it all to a string. I've attached my qvf if that helps. I was getting an error, but testing it with my data earlier, it did match up with my dimension numbers, but once I write it back, it doesn't seem to auto-populate as I wished. Any other steps I may be missing?