A lot of times I filter some table and expect that there will only be a single result.
[Subscriptions].Filter([Client] = thisRow and [Active?]).First()
To get that final result, I often call
First() has two problems:
- It doesn’t check that my filter only returns one result
- It doesn’t convey to the person reading my formula that there should only be one result.
If there was an
Only() formula, it could do both those things.
[Subscriptions].Filter([Client] = thisRow and [Active?]).Only()
- Now the person reading the formula understands that they can rely on that filter only returning one result
- The formula can return a useful error if it’s expectations are violated: “Only() expected a list with only a single value, but instead received [“A”, “B”, “C”].”
I could get around this by writing:
[Subscriptions].Filter([Client] = thisRow and [Active?]).WithName(ActiveSubscription, If(ActiveSubscription.Count() > 1, List(Max(List()), "Expected a List with only 1 entry (this is my sneaky way of throwing an exception)"), ActiveSubscription.First() )
Obviously, this is much much more verbose than just