Prevent data entry if reading already exists for the month

I have a water meter reading appsheet which you’ve helped with greatly. I have many questions on development, this is the latest:

The user enters the meter reading and it’s captured on the date of entry. I want to prevent another entry in the same month, for the same meter…I only want the users to enter a meter reading once per month. If the reading is June 30, and the next reading is July 1, that’s okay. Just don’t want a reading on June 10 and on June 30 for the same meter.

I’m in the “Valid_IF” section of the entry, but struggle with selecting the month for the second entry.

Not(In([_THIS], SELECT(Lecturas[Medidor],AND([Medidor]<>[_THISROW].[Medidor],MONTH([Fecha])=[_THISROW].[Fecha]))))

Tables below:

Please try in the valid_if

ISBLANK(
FILTER(
“Lecturas”,
AND ([_THISROW].[Medidor] = [Medidor], MONTH([Fecha])= MONTH([_THISROW].[Fecha]))
)

  • LIST([_THISROW])
    )
1 Like

Thank you so much. That appears to have been it. The part I don’t understand is the “-LIST(_THISROW)” part…I don’t understand the subtraction.

1 Like

That subtraction helps when the user tries to open and edit a saved record. Without the subtraction of the current record being edited, that record is also included in the FILTER() expression. This prevents the user from saving an existing record once opened because the valid_if works on that record as well once saved.

Also please note that such duplicate prevention approaches may fail at times if multiple users are trying to work simultaneously on the same record. The probability of happening this could be very small but still exists.

Please take a look at the last part of the help article on preventing duplicates.

List expressions - AppSheet Help

1 Like

Great explanaition! Thank you!

1 Like

You are welcome.