Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
All,
Here's my requirement
Should be done in script.
From:
Product, Value, RowNo
A,10,1
A,,20,2
B,30,3
B,40,4
to
Product, Value, RowNo
A,10,1
A,,20,2
B,30,1
B,40,2
Basically for each value of Product, the rowno() should reset and start from 1.
AutoNumber(RecNo(), Product) as Counter
-Rob
Currently trying with Peek. Let me know if you guys can solve it more quickly.
I think Peek is needed in script -
Source:
Load * inline [
Product, Value
A,10
A,20
B,30
B,40];
NoConcatenate
Final:
Load *,
if(Product=Previous(Product),Rangesum(Peek(Row_No),1),1) as Row_No
Resident Source;
Drop table Source
Excellent solution. I did this using 2 for next loops. Your solution is the best one liner ever rwunderlich
It's a good technique using AutoNumber. Note that it can be slow if there are many thousands of different Product values, in which case you revert to the previous/peek method.
-Rob
Just a quick clarification,
Here the product field is acting like the Auto ID right?
I would be happy if you could also explain what Auto ID does?
Thanks Rob!
Yes, Product is acting as the AutoId. AutoId establishes a separate counting sequence for each value of the AutoId.
-Rob
Thanks Rob 😁
Reviewing the documentation updated so far, there is no clear instruction about Autoid parameter can be a table field. To me I supposed it can only be string parameter inside single quotes.
As you commented, autonumber could be very slow compared to using previous and peek.
A colleague made a test on a 7 million rows dataset with thousands of distinct values on the key field.
Using autonumber, it took 50 minutes to process
Using sort/peek/previous it took only 4 minutes