Find next date in a list and give the column header

I am honestly not sure how to phrase my question without an example. 

 

ItemMonth 1 TimepointMonth 2 TimepointMonth 3 TimepointMonth 4 TimepointMonth 5 TimepointMonth 6 TimepointNext Timepoint
Apple04/14/202305/14/202306/14/202307/14/202308/14/202309/14/2023Month 1 (04/14/2023)
Banana11/13/202212/13/202201/13/202302/13/202303/13/202304/13/2023Month 5 (03/13/2023)

I want to make a virtual column (in this example, "Next timepoint" is the virtual column) that gives me the column header and date of the next timepoint. For example, if I wanted to retrieve the timepoint that is upcoming.

I am thinking that I could make a list of the dates for each item, remove past dates, and calculate the month duration of the first date that wasn't removed, which is assumed to be the next testing date. However, I haven't been able to get the proper syntax started.

Solved Solved
0 2 144
1 ACCEPTED SOLUTION

It's a lot easier to sort and select rows as compared to columns. You're likely better off segregating your Month Timepoint columns into a child table with each row referencing a parent item and having a single Month column. For example

Parent table

Item
Apple
Banana

Child table

Item Month Timepoint
     

Using your current data structure, there's no way to avoid needing a dense expression.

You could create a brute force series of comparisons:

IFS(
    TODAY() < [Month 1 Timepoint], CONCATENATE("Month 1 (", [Month 1 Timepoint], ")"),
    TODAY() < [Month 2 Timepoint], CONCATENATE("Month 2 (", [Month 2 Timepoint], ")"),
    ...
    )

Alternatively, you could try a more abstract INDEXOF technique:

CONCATENATE(
    "Month ",
    COUNT(
        SPLIT(
            ANY(
                SPLIT(
                    (" , " & SORT(LIST([Month 1 Timepoint], [Month 2 Timepoint], [Month 3 Timepoint], [Month 4 Timepoint], [Month 5 Timepoint], [Month 6 Timepoint], DATE(TODAY()))) & " , "),
                    (" , " & TEXT(TODAY(), "MM/DD/YYYY") & " , ")
                )
            ),
            " , "
        )
    ),
    " (",
    INDEX(
        LIST([Month 1 Timepoint], [Month 2 Timepoint], [Month 3 Timepoint], [Month 4 Timepoint], [Month 5 Timepoint], [Month 6 Timepoint]),
        COUNT(
            SPLIT(
                ANY(
                    SPLIT(
                        (" , " & SORT(LIST([Month 1 Timepoint], [Month 2 Timepoint], [Month 3 Timepoint], [Month 4 Timepoint], [Month 5 Timepoint], [Month 6 Timepoint], DATE(TODAY()))) & " , "),
                        (" , " & TEXT(TODAY(), "MM/DD/YYYY") & " , ")
                    )
                ),
                " , "
            )
        )
    ),
    ")"
)

View solution in original post

2 REPLIES 2

There is no Appsheet formula that can return the name of a column. You can achieve this, but you have to basically hard-code it like this:

IFS(
  [col1] = MAX( LIST( [col1],[col2]...)) , 
  "col 1" ,
  [col2] = ...
  ...
)

 

Your data structure is not very good, for this reason and more. A better structure would be like this:

Item Month Timepoint
apple 1 4/14
apple 2 5/14
apple 3 6/14

It's a lot easier to sort and select rows as compared to columns. You're likely better off segregating your Month Timepoint columns into a child table with each row referencing a parent item and having a single Month column. For example

Parent table

Item
Apple
Banana

Child table

Item Month Timepoint
     

Using your current data structure, there's no way to avoid needing a dense expression.

You could create a brute force series of comparisons:

IFS(
    TODAY() < [Month 1 Timepoint], CONCATENATE("Month 1 (", [Month 1 Timepoint], ")"),
    TODAY() < [Month 2 Timepoint], CONCATENATE("Month 2 (", [Month 2 Timepoint], ")"),
    ...
    )

Alternatively, you could try a more abstract INDEXOF technique:

CONCATENATE(
    "Month ",
    COUNT(
        SPLIT(
            ANY(
                SPLIT(
                    (" , " & SORT(LIST([Month 1 Timepoint], [Month 2 Timepoint], [Month 3 Timepoint], [Month 4 Timepoint], [Month 5 Timepoint], [Month 6 Timepoint], DATE(TODAY()))) & " , "),
                    (" , " & TEXT(TODAY(), "MM/DD/YYYY") & " , ")
                )
            ),
            " , "
        )
    ),
    " (",
    INDEX(
        LIST([Month 1 Timepoint], [Month 2 Timepoint], [Month 3 Timepoint], [Month 4 Timepoint], [Month 5 Timepoint], [Month 6 Timepoint]),
        COUNT(
            SPLIT(
                ANY(
                    SPLIT(
                        (" , " & SORT(LIST([Month 1 Timepoint], [Month 2 Timepoint], [Month 3 Timepoint], [Month 4 Timepoint], [Month 5 Timepoint], [Month 6 Timepoint], DATE(TODAY()))) & " , "),
                        (" , " & TEXT(TODAY(), "MM/DD/YYYY") & " , ")
                    )
                ),
                " , "
            )
        )
    ),
    ")"
)
Top Labels in this Space