Last giving date

Hi everybody…

I try to create app has two tables:
Table#1 consist of 4 columns {[Barcode col, date col, Next giving date col, and ID col]} where:

[date column] type date= initial value TODAY()
[Next giving date] type date= [date column]+2.
[ID]= uniqueid()

Table#2 consist of 5 columns {[Barcode col, date col, Last giving date, Result, and ID col]} where:

[barcode] ref type with table#1
[date column] type date= TODAY()
[ Last giving date] type date= [Barcode].[Next giving date]
Result type text=
IFS([Date]=[Last giving date], Deserve, [Date]>[Last giving date], Deserve, [Date]<[Last giving date], Do not Deserve)
[ID]= uniqueid()

I have problem in Table#2 with [Last giving date] col.
where if there are several dates that record in Table#1 with same barcode So the [Last giving date] col. does not record the nearest last date to the present date, it is recording random date for example:
12/5/2020
14/5/2020
16/5/2020
I want the [Last giving date] col. should record 16/5/2020
but It is record 14/5/2020 or 12/5/2020.

thank you in advance…

Solved Solved
0 13 390
1 ACCEPTED SOLUTION

Okay… I see two problems.

  1. The Last giving date and Result columns of the checking_form table are normal columns with App formula expressions. App formula expressions for normal columns are only recalculated when the row is edited in a form or modified by an action. So while you may be adding more rows you expect those App formula expressions to see, they do not and will not until the checking_form row is modified by a form or an action. Consider using virtual columns for these two columns instead: virtual column values are recalculated automatically each time the app syncs.

  2. Your expression for the Last giving date column in the checking_form table dereferences the value of the Barcode column of the same row. The Barcode column is of type Ref and refers to the bread_distribution table. A Ref value by definition is the key column value of exactly one specific row in the referenced table. Based on the name of the Ref column, and your expressed expectations, I suspect you believe the value of the Barcode column of the checking_form table is a value in the Barcode column of the bread_distribution table. In fact, the Barcode value in the checking_form table is a value of the _ComputedKey column in the bread_distribution table.

To get the behavior you want, where Last giving date provides the latest value of the barcode’s Next giving date values and Result provides an up-to-date result, I suggest the following:

  1. In the checking_form table, change the column type of the Barcode column to Text.

  2. In the checking_form table, set the Valid_If expression of the Barcode column to:

    SORT(
      SELECT(
        bread_distribution[Barcode],
        TRUE,
        TRUE
      )
    )
    
  3. In the checking_form table, convert the Last giving date normal column to a virtual column, with this App formula expression:

    MAX(
      SELECT(
        bred_distribution[Next giving date],
        ([_THISROW].[Barcode] = [Barcode])
      )
    )
    
  4. In the checking_form table, convert the Result normal column to a virtual column, with this App formula expression:

    IF(
      ([Date] < [Last giving date]),
      "Do not Deserve",
      "Deserve"
    )
    

See also:










View solution in original post

13 REPLIES 13

Steve
Platinum 4
Platinum 4

This means the barcode is not the key column of table #1. Key values cannot be duplicated within the same key column.

Given that the barcode is not the key column, I suspect the barcode column in table #2 does not actually contain a barcode value, but–since you say it’s a Ref to table #1–it should instead contain a value in the ID column of table #1, which is presumably the key column of table #1.

I suspect your key columns are wrong or corrupted.

Thank you Steve.
Yes ID column in table#1 is key column.
So, how can solve that?

Key column in table#1 is
CONCATENATE([Barcode],": ",[id])

@Steve
Sorry steve, How can I fix this issue?

Both of those statements cannot be true.

Please post screenshots of the column lists for both tables that include at least the key columns.

Please also post a screenshot of the complete expression for the Last giving date column.

@Steve
Table#1

_computedkey

Expression for the Last giving date

Thank you for those screenshots!

Please post screenshots of the column list for table #2 that includes at least the Barcode column, as well.

@Steve
Thank you Steve…

Table#2

Okay… I see two problems.

  1. The Last giving date and Result columns of the checking_form table are normal columns with App formula expressions. App formula expressions for normal columns are only recalculated when the row is edited in a form or modified by an action. So while you may be adding more rows you expect those App formula expressions to see, they do not and will not until the checking_form row is modified by a form or an action. Consider using virtual columns for these two columns instead: virtual column values are recalculated automatically each time the app syncs.

  2. Your expression for the Last giving date column in the checking_form table dereferences the value of the Barcode column of the same row. The Barcode column is of type Ref and refers to the bread_distribution table. A Ref value by definition is the key column value of exactly one specific row in the referenced table. Based on the name of the Ref column, and your expressed expectations, I suspect you believe the value of the Barcode column of the checking_form table is a value in the Barcode column of the bread_distribution table. In fact, the Barcode value in the checking_form table is a value of the _ComputedKey column in the bread_distribution table.

To get the behavior you want, where Last giving date provides the latest value of the barcode’s Next giving date values and Result provides an up-to-date result, I suggest the following:

  1. In the checking_form table, change the column type of the Barcode column to Text.

  2. In the checking_form table, set the Valid_If expression of the Barcode column to:

    SORT(
      SELECT(
        bread_distribution[Barcode],
        TRUE,
        TRUE
      )
    )
    
  3. In the checking_form table, convert the Last giving date normal column to a virtual column, with this App formula expression:

    MAX(
      SELECT(
        bred_distribution[Next giving date],
        ([_THISROW].[Barcode] = [Barcode])
      )
    )
    
  4. In the checking_form table, convert the Result normal column to a virtual column, with this App formula expression:

    IF(
      ([Date] < [Last giving date]),
      "Do not Deserve",
      "Deserve"
    )
    

See also:










@Steve
I am very appreciated you about this very detailed and helpful response.
I did all above expressions, but I faced problem with Barcode in checking table where it is auto record all barcodes that save in barcode column in bread distribution table as shown in screenshot below:

I don’t understand.

Steve.
In checking form the barcode column record barcode automatically that recorded in bread distribution table.
As shown in screen shot above.

@Steve
Thank you Steve…
I removed the first expression

Know is okay.

Top Labels in this Space