Page 1 of 1

Transformer logic: How to mark a record within a group once?

Posted: Mon Apr 30, 2018 2:31 am
by DS-mate
Hi folks,

I might have a simple question regarding transformer logic. My challenge is to determine if an error within a group occured once. If the first data in a group represents an error (marked as 1) for the first time, then the counter (AmountOfWrongGroup) should be set to 1 for the record. But if there are following erros within the group it should be set to 0.

For example:

Group-ID --- Error --- AmountOfWrongGroup
A 0 0
A 1 1
A 1 0
B 1 1
B 0 0
C 0 0
C 0 0

I tried by working with stage variables and building a search string per group, but I didn't get it work correctly :(

Do you have a clue? Thanks a lot!

Posted: Mon Apr 30, 2018 3:55 am
by ray.wurlod
Welcome aboard.

The trick is to set the stage variable to itself when you don't need to change it. For example, initialize svTest to 0.
Derive svTest as

Code: Select all

If <<error occurred>> And svTest = 0 Then 1 Else 0
You don't actually need the If..Then..Else. This Boolean logic will also work:

Code: Select all

<<error occurred>> And svTest = 0

Posted: Mon Apr 30, 2018 6:24 am
by DS-mate
Wow thanks for the fast response.

But what is if the data comes like:

Group-ID --- Error
B ------------- 1
B ------------- 1
B ------------- 1


Using the if clause you mentioned would return: 1,0,1 wouldn't it?

Thank you very much!

Posted: Mon Apr 30, 2018 7:24 am
by ArndW
svErrorsFound = IF In.Group-ID=svLastGroup THEN IF In.Error=1 THEN svErrorsFound+1 ELSE SvErrorsFound ELSE IF In.Error=1 THEN 1 ELSE 0
svErrorState = IF SvErrorsFound=1 THEN 1 ELSE 0
svLastGroup = In.Group-ID

The first stage variable Counts the number of "Errors" up, resetting when the Group Change occurs. The second stage variable, "svErrorState" is your Output column Derivation and the last stage variable defines your last record Group-ID value.