Set value in column "Current status" as result of selection from statuses log

Hello.

I have table when log values for estate object statuses are stored (table โ€œEstateObjectStatusesโ€).

There are two statuses: โ€œon saleโ€ and โ€œnot on saleโ€. Each row in โ€œEstateObjectStatusesโ€ has timestamp (column โ€œtimestampโ€).

Estate objects are stored in table โ€œEstateObjectsโ€. There is column โ€œcurrent_statusโ€.

So, I need somehow keep value in โ€œcurrent_statusโ€ as a selection of last status by timestamp for each object.

0 6 180
6 REPLIES 6

So I managed to get latest id by this expression:

MAXROW(
    EstateObjectStatuses,
    "timestamp",
    ([_THISROW].[estate_object_id] = [estate_object_id])
)

By this expression I get id from โ€œEstateObjectStatusesโ€ (โ€œestate_object_status_idโ€ column). But I need value of column โ€œstatusโ€!

MAXROW(
   ...
).[status]

Doesnโ€™t work.

Iโ€™ve done it by this expression:

SELECT(
    EstateObjectStatuses[status],
    (
        [estate_object_status_id] = MAXROW(
            EstateObjectStatuses,
            "timestamp",
            ([_THISROW].[estate_object_id] = [estate_object_id])
            )
    )
)

But is it correct?
Such a cumbersome expression for simple queryโ€ฆ

MAXROW() returns a REF, so to retrieve the value of the [Status] column, you need to de-ref the valur. Set a VC with the MAXROW() expression only and then use this VC column for de-ref
[VirtualColumn].[Status]

OR

ANY(
	SELECT(
		EstateObjectStatuses[status],
		[_RowNumber] = 
		MAX(
			SELECT(
				EstateObjectStatuses[_RowNumber],
				[_THISROW].[estate_object_id] = [estate_object_id]
			)
		)
	)
)

Yep, but thatโ€™s how AppSheet worksโ€ฆ


I can only suggest developers to take a look at Django ORM (sure they know but maybeโ€ฆ)

Top Labels in this Space