Prevent Duplicate Records in a Master-Detail relation

Hi community!!!
I’ve been trying to validate if a record already exists in a detail table to avoid adding the same service more than once.
There is no problem when is in a master table (1 single key), but I have not been able to validate when there is more than one key field.

This is the expression I’m using in Valid if,

COUNT(SELECT(Servicios[Id_Servicio],
AND([Id_Servicio]=[_THISROW].[Id_Servicio],
[Id_Cita_Servicio]=[_THISROW].[Id_Cita_Servicio])))=0

any ideas???

Thanks

In what way doesn’t that expression work?

I’m not sure if i’m explaining well …

Need to validadte if the “Servicio” in a “Cita” doesn’t exists before…

Your expression, reformatted for my clarity:

COUNT(
  SELECT(
    Servicios[Id_Servicio],
    AND(
      ([Id_Servicio] = [_THISROW].[Id_Servicio]),
      ([Id_Cita_Servicio] = [_THISROW].[Id_Cita_Servicio])
    )
  )
) = 0

What I suggest instead:

ISBLANK(
  FILTER(
    "detail-table",
    AND(
      ([Id_Cita] = [_THISROW].[Id_Cita]),
      ([Id_Servicio] = [_THISROW].[Id_Servicio]),
      ([_ROWNUMBER] <> [_THISROW].[_ROWNUMBER])
    )
  )
)

Replacing detail-table with the name of the detail table.

2 Likes

That was exactly what I was looking for. !!! Thank you so much Steve. :wink:

1 Like