How to set the initial value of an EnumList as I've tried everything and it does not work?

I have logged with support but haven’t got a solution yet so I’m turning to the community - you’re my only help!

I have made a simple text-based EnumList on the [Courses] column of a row in the Attendance table:

The goal is to make the initial value of this EnumList the same as the value for the same day last week and I’ve used this formula to get that data:

SELECT(Attendance[Courses], AND([Student] = [_THISROW].[Student], ([Date] = [_THISROW].[Date] -7)))

The formula works when tested:

As you can see for “John Rae” for today (06/03/2024) the returned value is “English , Science” which is the value of [Courses] from the previous week. Yet this does not set the [Courses] for today when used as the initial value.

I even tried simply setting the initial value to be LIST(“English”,“Science”) and still the EnumList was not set.

I thought it was maybe the fact that the Editable formula was preventing an initial value, but I tried removing it and still it’s not working.

Any ideas are greatly appreciated.

Not sure if this will solve your problem, but there are some issues when using SELECT() of an EnumList column, because it quasi returns a list of lists. So try the following to see if it works correctly:

ANY(SELECT(Attendance[Courses], AND([Student] = [_THISROW].[Student], [Date] = ([_THISROW].[Date]-7))))

Try this first, if you still have issues then we can start exploring some other possibilities.

1 Like

In your screenshot I cannot see an item separator specified for your enumlist column?

It looks as if your Select formula is returning the items as a space comma space separated list?

So try adding space comma space as the item separator for your enumlist column and see if you get any joy?

2 Likes

@Markus_Malessa thank you for the suggestion: I think I tried that earlier but, nevertheless, I tried it again and there’s no difference: there’s still no initial value.

I’m more concerned that I can’t even get an initial value if I simply just specify it manually asa list, i.e.

LIST("English","Science")

Didn’t work either, so I’m confused about what is acceptable as an initial value.

As @scott192 pointed out, pay particular detail to your separator for your enumlist. The default I think is " , " (space comma space). Just for additional testing see if you can preset the initial value like this:

{"English" , "Science"}

I think @Markus_Malessa is correct in his causal analysis.

Please try an expression of

SPLIT(TEXT(SELECT(Attendance[Courses], AND([Student] = [_THISROW].[Student], ([Date] = [_THISROW].[Date] -7)))) ,“,”)

A SPLIT() will help flatten the list of lists into a simple list.

1 Like

Emphasis on “flatten the list”. I think Google needs to absorb that term into their documentation.

Have you noticed any difference using SPLIT(TEXT(SELECT())) vs just SPLIT(SELECT()) when using select on EnumList columns?

If my memory serves me right, I think @Marc_Dillon had made this nice suggestion of using TEXT() first before using SPLIT() as use of only SPLIT() fails at times. I will post his recommendation post , if I can find it on search. I had found his recommendation very useful and it always works.

Also I believe the “flatten the list of lists” term was used by @Steve first. It is so appropriate for the case.

1 Like

Hi @Markus_Malessa ,

Here is a post on TEXT(SPLIT(…)) by @Marc_Dillon

Solved: Split in Valid_If not allowing me to select and sa… - Google Cloud Community

I believe there are more posts as well in this regard by him.

1 Like

Yes, always use the TEXT() first. This makes sure to retain the standard space-comma-space delimiter, which you can then SPLIT() by. Using just SPLIT by itself tries to use a different delimiter, which can work in some cases, but it also produces erratic behavior in some other cases.

2 Likes

Thank you Marc for putting it succinctly.

Many thanks for all the suggestions: none have worked so far:

  1. I manually specified space comma space as the item separator and that made no difference

  2. I tried manually assigning the initial value as

    {"English" , "Science"}​
    

    and it didn’t set initial value

  3. I tried various combinations for the new idea on flattening the lists: which looks like there must be some kind of list of lists going on:

    SPLIT(TEXT(SELECT(Attendance[Courses], AND([Student] = [_THISROW].[Student], ([Date] = [_THISROW].[Date] -7)))))​
    

    When I test gives an interesting response of

    English , , , Science
    

    I tried combining with ANY (as there should only be one result):

    SPLIT(TEXT(ANY(SELECT(Attendance[Courses], AND([Student] = [_THISROW].[Student], ([Date] = [_THISROW].[Date] -7))))))​
    

    but got exactly the same

    I tried adding TOP() also as another way to get only 1 and still no good.

SPLIT(TEXT(SELECT(Attendance[Courses], AND([Student] = [_THISROW].[Student], ([Date] = [_THISROW].[Date] -7)))))​ - LIST()

Add the - LIST() to the formula of your interesting response…this will remove the empties. Edit* You may have to wrap the intial part of the formula in a LIST() expression first.

LIST(SPLIT(TEXT(SELECT(Attendance[Courses], AND([Student] = [_THISROW].[Student], ([Date] = [_THISROW].[Date] -7)))))​) - LIST()

Sorry there was some part missing in my earlier suggestion, that I had corrected in the same post. Please note a “,” at the end of the expression that needs to be there.

I addition, it is more worrying that you cannot set an initial value. Have you got something set in the Validate section of that column?

Should be: " , "

1 Like

I think I have found the issue and it’s nothing to do with any of the formulas: I’m trying to edit an existing row, rather than making an entirely new row: I didn’t realise that if it’s a pre-existing row and you edit/quick edit from a detail view then even if the column is empty you don’t get the initial value.

I need to take a different approach, e.g. use a bot to set the values when the row gets created.

I’m disappointed that support has not spotted any of this in our interaction that I’m trying to do something that AppSheet cannot do (yes I can set the “Reset on edit?” option, but I don’t want that if there’s actual data there).

Thanks for all the suggestions as they will be useful in the future.

You could put a formula on the column’s Reset on Edit section so that if you make any changes to the row and the current value of your enumlist is empty then it will fill in the initial value again?

Can you clarify why you are trying to edit an existing row? Or are you using copy the current row into a new form functionality? If this is a new attendance row under a student for example I am unclear why editing a current row would be necessary.

Marc. , oh , yes my bad for that inadvertent but vital miss of spaces.