Page 1 of 1

Issue

Posted: Mon Sep 20, 2010 10:17 am
by rsunny
Hi everyone,

I have one more problem, I need to add one more field as row in my task and i have to get the row number based on the group i.e.
If i have three columns say company code, product code, amt.
I need to add another column for the rows. the output should come in this way.
abc,coke,120,1
abc,coke,140,2
abc,pepsi,30,1
abc,pepsi,40,2
abc,pepsi,240,3
cdf,coke,60,1
cdf,pepsi,50,1

I tried to compare with the previous record and if they are same i tried to increment but i could able to solve it for two rows but if there are more than two rows its not working ,can any one suggest me the code for this problem.

Thanks in advance

Posted: Mon Sep 20, 2010 10:21 am
by arunkumarmm
How you tried this? Can you post your approach?


Also, did you sort your rows before that? And did you include both company code and product code to validate?

issue

Posted: Mon Sep 20, 2010 10:47 am
by rsunny
i first sorted and grouped based on sort and aggregator function.after that i used stage variables to compare with the previous and current record .but initially i asigned the row column as a constant variable.

Posted: Mon Sep 20, 2010 11:47 am
by asorrell
Please post your actual code. We can't fix it if we can't see it.

Posted: Mon Sep 20, 2010 12:40 pm
by arunkumarmm
I dont have a clear understanding on your approach but If i'm doing this I will try something like this:

Code: Select all

Sort rows using company code and product code.
Assign the initial values for all stage variables as empty ( '' )
 svOldComp = svNewComp
svNewComp = Link1.CompCd Column
 svOldPrd = svNewPrd
svNewPrd = Link1.PrdCd Column

svSeqNum = If svNewComp <> svOldComp And svNewPrd <> svOldPrd Then 1 Else If svNewComp = svOldComp And svNewPrd <> svOldPrd Then 1 Else If svNewComp = svOldComp And svNewPrd = svOldPrd Then svSeqNum +1 Else 1
I have not tested this but this should work.

Posted: Mon Sep 20, 2010 6:40 pm
by rsunny
arunkumarmm wrote:I dont have a clear understanding on your approach but If i'm doing this I will try something like this:

Code: Select all

Sort rows using company code and product code.
Assign the initial values for all stage variables as empty ( '' )
 svOldComp = svNewComp
svNewComp = Link1.CompCd Column
 svOldPrd = svNewPrd
svNewPrd = Link1.PrdCd Column

svSeqNum = If svNewComp <> svOldComp And svNewPrd <> svOldPrd Then 1 Else If svNewComp = svOldComp And svNewPrd <> svOldPrd Then 1 Else If svNewComp = svOldComp And svNewPrd = svOldPrd Then svSeqNum +1 Else 1
I have not tested this but this should work.
Do we need to initialize the svseqnum or is it not required as ther will be empty value in svseqnum if we dont initialize

Posted: Mon Sep 20, 2010 6:43 pm
by rsunny
my code is

i had taken rowcount as a seperate column and initialized to 1
then i had written
crc32(Nulltoempty(comcode):nulltoempty(procode))=stagevar1
if stagevar1=stagevar2 then rowcount+1 else 1=stagvar
crc32(Nulltoempty(comcode):nulltoempty(procode))=stagevar2