tgrosinger / md-advanced-tables

A text editor independent library to enable formatting and Excel-style navigation, and spreadsheet formulas to Markdown tables.
MIT License
149 stars 30 forks source link

Add formula cross referencing (with multiple tables) #40

Open scarfur opened 2 years ago

scarfur commented 2 years ago

First of all - thank you so much for this plugin 👍

May I ask if this (title) could be a thing in the future? Would be awesome to, for example, sum up values from table1 with values from table2 in table2. Another example: fill a cell in table2 with a value from table1 and then sum it with another value from table2.

tgrosinger commented 2 years ago

@scarfur, I'm not sure how that could be implemented robustly in markdown. Do you have suggestions for how you would reference the other table? The only thing that comes to mind right now is line numbers, but that sounds very fragile.

scarfur commented 2 years ago

@tgrosinger Referencing on lines seems to fragile, that’s true. Mr. Valentine uses ^tablename-next-line-under-table in his dice roller plugin (https://github.com/valentine195/obsidian-dice-roller), maybe that helps?!

carllemp commented 2 years ago

Maybe YAML could allow for some cross referencing if a table cell could reference a YAML key and the html comment that defines the formula could be enhanced. Instead of:

a format like Could assign the calculated value to both the table location (@>$3) and to a YAML key (Keyname). or Could assign the calculated value to a YAML key (YAMLKeyname). And then that YAML value (or any other) could be pulled into a table cell by linking to the YAML key in the cell instead of pushing the value into a cell through the formula itself? I think the 2nd option above would also allow calculated table values to be queried and summarized using plugins like DataView.
quantimnot commented 2 years ago

I am new to Obsidian and Org-Mode. I have no experience or knowledge in this area, but I was looking for a means to accomplish this. I noticed that Org mode supports this:

#+NAME: supplies
| Date       | Category         | Amount |
|------------+------------------+--------|
| 2014/01/14 | Supplies         |  43.97 |

#+NAME: expenses
| Category                 | Amount                       |
|--------------------------+------------------------------|
| Office Supplies/Expenses | :=remote(supplies,@>$3);%.2f |

Could this be possible:

<!-- TBLID: expenses -->
| Item      | Cost | Qty |
| --------- | ---- | --- |
| groceries | 666  | 1   |

| Item      | Monthly |
| --------- | ------- |
| groceries |         |
<!-- TBLFM: $>=remote(expenses, ($2*$3)) -->

Maybe a way to reference a table in a separate document:

| Item      | Monthly |
| --------- | ------- |
| groceries |         |
<!-- TBLFM: $>=remote(document, expenses, ($2*$3)) -->