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

Solved Solved
0 4 115
1 ACCEPTED SOLUTION

Steve
Platinum 4
Platinum 4

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.

View solution in original post

4 REPLIES 4

Steve
Platinum 4
Platinum 4

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…

Steve
Platinum 4
Platinum 4

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.

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

Top Labels in this Space