How do I limit the number of times the same value is added to a table

LLD
Silver 2
Silver 2

Hello,

I have two tables -

  • one containing box details including box numbers (unique; key field)
  • another containing master cartons details, including master carton numbers (unique; key field)

A master carton can hold 4 boxes.

  • A box cannot be added to more than one master carton.
  • Each master carton can hold 4 boxes or less
  • A box may be removed from a master carton (and another may be added in its place)

The box table has a reference column for master carton numbers. Every time a box goes into a master carton, I add the master carton number to the boxโ€™s record (i.e. row) from the reference list.

  1. How do I ensure that a master carton number is not added to more than 4 boxes?
  2. Different types of master cartons have differing capacities. If I have a โ€œcapacityโ€ column for each master carton, how do I limit the addition of boxes to a master carton, w.r.t. itโ€™s capacity?
Solved Solved
0 5 209
  • UX
4 ACCEPTED SOLUTIONS

Steve
Platinum 4
Platinum 4

In the Valid If expression for the master carton number column of the box details table:

(
  COUNT(
    FILTER(
      "box details",
      AND(
        ISNOTBLANK([master carton number]),
        ([master carton number] = [_THISROW].[master carton number]),
        NOT([_ROWNUMBER] = [_THISROW].[_ROWNUMBER])
      )
    )
  )
  < 4
)
(
  COUNT(
    FILTER(
      "box details",
      AND(
        ISNOTBLANK([master carton number]),
        ([master carton number] = [_THISROW].[master carton number]),
        NOT([_ROWNUMBER] = [_THISROW].[_ROWNUMBER])
      )
    )
  )
  < [master carton number].[capacity]
)

See also:

View solution in original post

Thank you for this Steveโ€ฆ works like a charm!

However, how do I prevent a full master carton from appearing in the reference list of master cartons?

View solution in original post

Try using this as the Valid If expression:

FILTER(
  "master cartons",
  (
    COUNT(
      FILTER(
        "box details",
        AND(
          ISNOTBLANK([master carton number]),
          ([master carton number] = [_THISROW-1].[master carton number]),
          NOT([_ROWNUMBER] = [_THISROW].[_ROWNUMBER])
        )
      )
    )
    < [capacity]
  )
)

View solution in original post

@Steve, this helped me understand FILTER() even better. Thank you.

View solution in original post

5 REPLIES 5

Steve
Platinum 4
Platinum 4

In the Valid If expression for the master carton number column of the box details table:

(
  COUNT(
    FILTER(
      "box details",
      AND(
        ISNOTBLANK([master carton number]),
        ([master carton number] = [_THISROW].[master carton number]),
        NOT([_ROWNUMBER] = [_THISROW].[_ROWNUMBER])
      )
    )
  )
  < 4
)
(
  COUNT(
    FILTER(
      "box details",
      AND(
        ISNOTBLANK([master carton number]),
        ([master carton number] = [_THISROW].[master carton number]),
        NOT([_ROWNUMBER] = [_THISROW].[_ROWNUMBER])
      )
    )
  )
  < [master carton number].[capacity]
)

See also:

Thank you for this Steveโ€ฆ works like a charm!

However, how do I prevent a full master carton from appearing in the reference list of master cartons?

Try using this as the Valid If expression:

FILTER(
  "master cartons",
  (
    COUNT(
      FILTER(
        "box details",
        AND(
          ISNOTBLANK([master carton number]),
          ([master carton number] = [_THISROW-1].[master carton number]),
          NOT([_ROWNUMBER] = [_THISROW].[_ROWNUMBER])
        )
      )
    )
    < [capacity]
  )
)

@Steve, this helped me understand FILTER() even better. Thank you.

LLD
Silver 2
Silver 2

just brilliantโ€ฆ thanks!

Top Labels in this Space