The ListCombine()
formula is great for merging two or more lists or items together, however, it has this peculiar habit of flattening the output. I understand this is helpful most of the time (especially for non-programmers) because it means we don’t have to worry about flattening or not after adding items or lists to our list.
However, sometimes I really do want to add a list as an element in my list of lists.
- Example 1: I have a list of key-value pairs (from a table or generated otherwise)
-
Example 2: I have a list of date ranges, each represented by a list of two dates:
[start, end]
.
Now say I have two such lists and I want to combine them for one single FormulaMap or something. So far, the best solution I can think of is to use a Sequence formula like this:
Sequence(1, Count(OldList) + Count(NewList)).FormulaMap(
If(CurrentValue<=Count(OldList),
OldList.Nth(CurrentValue),
NewList.Nth(CurrentValue-Count(OldList))))
which basically does exactly the same thing as ListCombine(OldList, NewList)
except the output is not flattened… and it takes up more time and space to write
Furthermore, if either list is generated by a formula itself, then the above formula becomes ludicrously long.
Anyone have any other creative solutions?