Skip to main content

trying to extract using @GetNextValue

I'm trying to extract the next-closest accounts that have a Y or " " in the clc_titular field. I'm using @GetNextValue, but the formula throws an error in the equation.

I'm only interested in extracting the accounts that are related and... with the same account that is blank, as shown in the case.

And relationship

' Datos: Extracción directa
Function DirectExtraction
Set db = Client.OpenDatabase("Clientes_Mancomunado.IMD")
Set task = db.Extraction
task.IncludeAllFields
dbName = "EXTRACCIÓN1.IMD"
task.AddExtraction dbName, "", "@if( CLC_CUE == @GetNextValue(""CLC_CUE""),@CompIf( CLC_TITULAR =""Y"", @compIf( CLC_TITULAR ="" "" ,1,0)))"
task.PerformTask 1, db.Count
Set task = Nothing
Set db = Nothing
Client.OpenDatabase (dbName)
End Function

mod count
4 40101933 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TITULAR PRINCIPAL Y
4 40101933 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TITULAR
4 40101933 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TITULAR Y
4 40101933 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TULAR Y
This is how the report should appear.
Or something like this.
mod count
4 41000421 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TITULAR PRINCIPAL Y
4 41000421 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TITULAR

Brian Element Mon, 05/26/2025 - 12:18

I think the error is because of having an @compif within a @compif, more than likely it is getting confused.

Could your function not be rewritten as the following?

"@if( CLC_CUE == @GetNextValue(""CLC_CUE"") .AND. (CLC_TITULAR =""Y"" .OR. CLC_TITULAR ="" "") ,1,0)"

So if the value in the next CLC_CUE field is equal to CLC_CUE and CLC_TITULAR is equal to Y or a space in the current row, return 1, if not return 0.