Automatically select a default

I have a child table with phone numbers. In the parent table I have a field called default phone number that allows the user to select a default phone number from the list of numbers in the child table.
I use the following Valid_if expression for this:
SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:])

This works, but I want the default phone number to be entered automatically if there is only 1 phone number in the child table.

I have used the following App formula expression:

IF(COUNT(SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:])) = 1, ANY(SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:])), “”)

The expression works in the sense that a default phone number automatically gets picked when there is only one phone number. However, when there is more than one phone number in my child table, the default phone number field disappears completely.

I was hoping that the “” part in my expression would leave the field blank and that it would allow me to select a default phone number manually.

Any help would be much appreciated.

@Guillermo_Perez
You can construct your expression like this:
[INITIAL VALUE]

IFS(
	COUNT(SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:])) = 1,
	ANY(SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:]))
)

[SUGGESTED VALUES]

IFS(
	COUNT(SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:])) > 1,
	SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:])
)

Another approach might be like this:
This approach will put the phone numbers into a dropdown even it’s only one and always select the 1st value on the list as an initial value.
[INITIAL VALUE]

ANY(SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:]))

[SUGGESTED VALUES]

IFS(
	COUNT(SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:])) >= 1,
	SELECT(Phone_Numbers[Phone Number:], [Company:] = [_THISROW].[KEY:])
)
2 Likes

See the Preferred Value example here:

@LeventK and @Steve

Thanks for your help so far. I have tried all the methods described by you, but unfortunately I am not getting the desired results.
No default phone number is selected automatically (I believe this might be due to the expression being in the initial value column). I have tried this with existing entries and while trying to create new entries.

I don’t quite understand why the field disappears when I enter a app formula expression. Is there a way to achieve it with a app formula expression without the field disapearing when there is more than one phone number in the child table ?

@Guillermo_Perez
Initial Value does not re-calculate its value when editing an existing row if you haven’t explicitly turn on Reset on edit property and set an expression. Only AppFormula will be re-calculated with editing the row but you cannot edit its value. If your set parameters are correct in the expressions, it should work as expected.

1 Like

Thanks! I feel like such a fool for forgetting about the reset on edit property. It all works as expected now.

1 Like