How to get column name? (To generate )

I have a simple concatenation thing in Sheets, and I cannot figure out for the life of me how to do this in Coda.

How can I reference column name in a formula?
Or, really the same question, can I generate a list of column names of another table?

I feel like I may need multiple tables or something, that the spreadsheet approach is too foreign here.
This kind of concatenation has been very useful to me for various database imports, but maybe Coda has a better way to go around this.

Thanks!

Hi,

Assuming that the column headers wonā€™t be changing, you can just add them to the Concatenate Formula

=Concatenate("part1=",thisRow.part1,"part2=",thisRow.part2,"part3=",thisRow.part3)

Thanks for the suggestion @SK209. That would indeed work.

Alas - but thatā€™s not why Iā€™m posting here :slight_smile:
It can always be hardcoded, but the question is how to pull the ā€œpart_nā€ in programatically/ how to set it up for that.

Column names in Coda are some kind of identifiers, like variable name in programming language. It is not a good practice to change variable name dynamically, because other parts of the program may refer to it. Althought modern IDE allows you to rename variable in the entire program, this is still should be done before compilation or interpretation, by hand. Since Coda document is a program that re-interprets itself permanently, I think there is technically almost impossible to change column name from the inside.

And since you can change it only by hand, hardcoding method is pretty close to what you want in my opinion.

P.S. In your example on the screenshot column names are ā€œA, B, Cā€, not ā€œpart1ā€, ā€œpart2ā€, ā€œpart3ā€. For the program these texts are just a content of cells in the first row. So maybe your problem solves with some architectural changes, when this parts shouldnā€™t be ā€œColumn namesā€, but should be values of some property.

1 Like

At the risk of being a bit presumptuous about the intention of the answers above (sorry @Denis_Peshekhonov and @SK209!), the short point is that if you run into this type of problem in Coda, thereā€™s a good chance you should be restructuring your data (in this case, the ā€œpartsā€) so that it iterates across rows rather than across columns. Could you give a little more detail about the context of your example above? Iā€™d be happy to work up an example to show you what I mean, but would like to understand a bit more about what you are trying to achieve (the very generic nature of the dummy data in the screenshot above makes the context a bit obscure).

2 Likes

Totally agree with @Tim_Sherman. Some more context into your exact requirements or use case would help us bring forth a solution that is compatible with Codaā€™s database like structure.

Thatā€™s fair. I felt that I probably need a different data structure, I am just not used to thinking this way. This use case should help me getting there.

Use case:

I have a system with objects that have attributes. Letā€™s say objects are cars and attributes are color, make, special_power. I need to have the attributes as a comma separated list csv_attributes.

car = {
    car_id : 111
    color : red
    make  : honda
    special_power : levitation
}

What I desire is a table in the end, that looks like this:

car_id color make special_power csv_attributes
111 red honda levitation car_id=111,color=red,make=honda,special_power=levitation

:question: NOW, the question was how to do this without hardcoding the ā€˜attribute nameā€™. I want to either pull the attribute name from the column name, or I want to pull the column name from the attribute name. The point is I donā€™t want to be typing the attribute name twice anywhere. It should be only in one place. It can even be a table with Attribute Namesā€¦ but then how can I make a column name correspond to thatā€¦ Iā€™m getting lost again :slight_smile:

Outro:

Does this help illustrate the case?
Thanks for your suggestions!

Pretty clear, thanks! You problem is that you have external data format which you want transfer to. In ideal world I would give this job to an external module that uses API.

If you want to do it entirely inside document, there is the way. Your data structure is very similar to what non-relational databases do, e.g. MongoDB. Each record there has an unique indentifier _id, and the name of this field canā€™t be changed, but all other fields can: In this case field names are also part of data, not structure.

4 Likes

Thanks so much. I have to think about this some more. This certainly IS a real database now and it works :slight_smile: and I really like the use of FormulaMap(). The downside is that I lose the ā€˜normal spreadsheetā€™ form altogether, which makes this more difficult as a middle man for import and export . Or at least if I want to copy paste. Maybe I can add another step of piping it into this form. Maybe itā€™s time to API the spreadsheet into a databaseā€¦ which of course Coda is. Iā€™ll need to think some more.

Yes, this is one of the main drawbacks when you are choosing between relational and non-relational databases. Coda is definitely closer to relational style, but it needs more strict schema.

You are welcome )

P.S. There is now Integromat Coda integration, so maybe you can automate Coda->CSV transformation without writing your own program.

1 Like

It sounds like he simply wants to reference the name of the column, not change it.