I needed a single formula (not a Button) to transpose the Rows and Columns of a table.
Max
How It Works
each line explained…
The resulting display is the contents of the Original table with the rows and columns transposed
Max
This is awesome!
Thank you so much for all of your contributions to the community. Your posts are always so insightful and are true gems for Coda enthusiast.
ok… i looked at my code and realized it was twice as long and complicated as needed.
so i have reduced it to a more manageable minimal set of code.
here is the result (as before, its a ‘virtual’ transposed table - display-only)
and here is the shorter formula…
How It Works line-by-line
This runs faster, has less moving parts, and is easier to follow.
Someone asked why the _Code()? it shows the cells in a fixed-width font. otherwise the width of each cell would be slightly different and they would not align properly.
Max
@Agile_Dynamics, one would think I no longer would be surprised by all the gems you publish, and yet, one’d be wrong.
This is incredible, thank you SO much for so generously sharing your findings with the community.
In order to make your wondeful contribution accessible to as many interested readers as possible, I have taken the step-by-step overview you included and broke it down into displaying the formula results for each step.
It helped me much faster understand what your code does, and I’m thinking it might serve the same purpose for others.
I’m sharing the doc in an fully editable view, so that everyone can peek inside the formula editor - please do make sure not to delete anything, as this would sour the experience for others.
Max, what a community champion you are, indeed. Thanks so much for all you do for our Coda community!
All the best from Austria,
Nina
thanks @Nina_Kastenauer1,
you did a great job breaking it down, explaining it well, and displaying all the intermediate results.
much appreciated
max
Recently, I was searching for a way to dynamically represent data in a virtual table (that is, moving from a “one-to-many” relationship to a “one-to-one” relationship without the user having to press a button to achieve this.
@Agile_Dynamics graciously took the time to share his wisdom with me on how to best achieve this. The second thing he said once I finally cracked it (after “Congrats!”) was “Now you must share your solution with the community”. And, as is usually the case, he was right of course. So, here goes:
Imagine we want to schedule a team retreat. While the scheduling is under way, we want to dynamically keep track of the number of times each team member interacts with every team member.
That is, we want to dynamically visualize Interactions Scheduled, ie how often does each team member meet with every other team member?
We will create the virtual table in the following two ways:
And here are the formulas used (I decided to include a static header, as well as a static side-bar, to ensure that the 2D-Matrix could easily be read by the user)
And to display as colored circles, simply add a “Switch-If” to the formula to display a green circle to represent the value 1, a yellow circle to represent the value 2, etc.
Enjoy,
Nina
Yet again I needed a sinple formula to display a TABLE in a TRANSPOSED format (ie swap rows and cols)
And I found an even SIMPLER solution…
In case anyone is interested, I have figured out how to create, modify and display vistual tables in Coda.
Sometimes it is useful to represent a table as a matrix; M, aka, list of lists.
Formulas can address arbitrary values using
M.nth(I).nth(J)
We also can use the Apache Parquet form for virtual tables. Where the first column is the row-identifier and the last column is a list of the column names. This is used in ‘big data’ applications to load large SQL tables into memory for faster processing.
We have done this in Coda as follows;
Create a virtual table V from a coda table P which has columns Product, Size, Quantity, Price…
Which produces a list-of-lists like this…
We GET the cell for row & col as follows (where row=id of the row, col=name of the column) as follows;
We can MODIFY a cell for row & col using the splice() formula as follows
The result is a new virtual table with the single cell at row & col changed to value
Note that this is NOT an action formula. So it does not need to be in a BUTTON or AUTOMATION.
We can manipulate virtual tables inside ordinary column formulas (or canvas formulas).
The resulting virtual table is updated immidiately without the need to click a button.
We can display the virtual table using this code…
I have made a pack for all this (and many more operations) for my clients.
If anyone is interested, I can get permission to publish it to the gallery.
Max
what a wonderful contribution @Agile_Dynamics , i am looking forward testing it myself by following your steps. This contribution also speaks to me because I believe we need this kind of transpose logic supported by coda with functions. For now this is an interesting way to move forward, merci!
The pack sounds like a great option for quick application.