How do I print the number of consecutive days in the child table to the main table

Hi,

I have two tables as I have shown below, one is a habit table and the other is a child table,

I want to print the latest serial number of days to the virtual column in the habit table.  (sample 19.03, 20.03, 21.03     3 days )

What should be the VC formula?

Habit Table     

ID    Habit Name     Virtual C.(  number of consecutive days)

1         Habit 1               3

2         .

3         .

Record Table

ID  Habit ID    Habit Name           Date                 Goal

1           1                 Habit 1            21.03.2023              Yes

2          1                 Habit 1            20.03.2023            Yes

3          1                 Habit 1            19.03.2023              Yes

4          1                Habit 1            18.03.2023             No

5          1                 Habit 1            16.03.2023            Yes

6          1                 Habit 1            15.03.2023            Yes

7           1                 Habit 1            14.03.2023           No

 

 

 

Solved Solved
0 10 150
1 ACCEPTED SOLUTION

That's a rough ask for Appsheet. Here's one way, not promising that it's the best way though.

I would start by adding a new column to the record table that is a Ref to the previous record.

ANY(FILTER( record , AND( [habit]=[_THISROW].[habit] , [date] < [_THISROW].[date] ) ) )

Then another new column to count of the number of consecutive days.

IF( [newcol1].[date] = [date]-1 , [newcol1].[newcol2] + 1 , 1 )

Then back in your parent table, add a new column to Ref to the latest child record

ANY( ORDERBY( [related records][key col] , [date] , descending ) )

And yet another column to pull the consecutive days value from the latest record

[latest_record].[newcol2]

 

 

View solution in original post

10 REPLIES 10

That's a rough ask for Appsheet. Here's one way, not promising that it's the best way though.

I would start by adding a new column to the record table that is a Ref to the previous record.

ANY(FILTER( record , AND( [habit]=[_THISROW].[habit] , [date] < [_THISROW].[date] ) ) )

Then another new column to count of the number of consecutive days.

IF( [newcol1].[date] = [date]-1 , [newcol1].[newcol2] + 1 , 1 )

Then back in your parent table, add a new column to Ref to the latest child record

ANY( ORDERBY( [related records][key col] , [date] , descending ) )

And yet another column to pull the consecutive days value from the latest record

[latest_record].[newcol2]

 

 

After newcol2 I get the error "Unable to fetch app definition. Ran out of resources evaluating: IF"

Wow, do you have a lot of data? The first 2 columns can be real.

No, there is not much data, the main table has 15 rows, the record table has 45 rows.

No problem when using real column, also

ANY(FILTER( record , AND( [habit]=[_THISROW].[habit] , [date] < [_THISROW].[date] ) ) ),

ANY( ORDERBY( [related records][key col] , [date] , descending ) )

I used maxrow instead, thank you for showing the way.

 

 
 
 
 
 

MAXROW is fine for the first of those 2, but I would stick to my expression for the 2nd. MAXROW must search the entire table, my expression only searches the related records.

I did as you said. "first expression maxrow" second expression is much faster sync as you suggested. Thanks

Search for @MultiTech 's post on looping.  He also has a video in his Youtube channel specific to this.

Can you share the link? @JPAlpano  Thanks.

Top Labels in this Space