Dynamically selecting columns

#1

Is there some easy way to index a table along the other axis dynamically, e.g. say I have a table A with a column named “John” and in some cell in another table (say B), I also have “John”, and I’d like to sum over the correct “John” column without hardcoding it (so it still depends on the value in table B)?

1 Like
#2

@Robin_Jadoul

I honestly don’t understand your question. However, this concept:

…leads me to think that maybe you’re wanting to iterate over columns? If so, I often find Switch() and SwitchIf() to be useful for that purpose.

Perhaps if you restate your question differently, or include a screenshot of what you’re attempting, I could be of more help.

#3

Sorry for being a bit unclear :slight_smile:
Perhaps this screenshot could clarify things a bit, basically, I want to use some string to select the values of a column as a list

1 Like
#4

@Robin_Jadoul

If “John” and “Jane” are required to be columns rather than rows, below is the only way I know of to accomplish what you’re after. Someone else may have a different answer.

If you only need the one row “John” in B, you can just use If() instead of SwitchIf().

If you don’t require any If() logic at all, then in B.Sum, you can just type =A.John.Sum().

1 Like
#5

Dear @Robin_Jadoul

In the screenshot below I have a table “Messages” where all incoming subjects are listed.
In the table “relatie beheer” I have listed for each person the LATEST ISSUE and ALL subjects. (last 2 columns of “relatie beheer”)

Formula in “Laatste thema”

Messages.Lookup(Persoon,thisRow).Onderwerpen.Last()

Formula in “alle onderwerpen”

Messages.Lookup(Persoon, thisRow).Onderwerpen.sort().BulletedList()

:bangbang: Take care that the display columns in both tables are with the same content, in my case the person’s names

I hope this will guide you in the right direction

Amicable,
//JP

1 Like
#6

Thanks for your suggestions, @Ander, @Jean_Pierre_Traets

Unfortunately, it would now seem that I’d need a more complex schema design , something I had hoped to avoid for the quick and dirty utility I was trying to build for myself.

Because I either still have to hardcode the columns and switch on a string value (which I had hoped not to have to do), or normalize my tables to have those column names as separate values per row instead :slightly_frowning_face:

2 Likes
#7

I’m also stuck with exactly this!
It might not be possible currently. If you do find a solution, please let us know here.