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

horizontal sums #70

Open JohannaTe opened 1 year ago

JohannaTe commented 1 year ago

Hi,

I'm having troubles getting a sum going that is more than two cells horizontally. The system tells me it cannot parse it. Would you be able to let me know how to fix this?

Thanks so much! Jo

This does not work:

I II III iv sum
2 3 5 6
Screenshot 2023-10-03 at 7 55 06 AM
khorton commented 1 year ago

Each individual math operation must be enclosed in parentheses.

Try:

| I   | II  | III | iv  | sum |
| --- | --- | --- | --- | --- |
| 2   | 3   | 5   | 6   | 16  |
<!-- TBLFM: @2$5=(@2$1+(@2$2+(@2$3+@2$4))) -->
khorton commented 1 year ago

Also, you can leave out the column specifier "@2". This is less typing, and it will allow one formula to work for several rows.

| I   | II  | III | iv  | sum |
| --- | --- | --- | --- | --- |
| 2   | 3   | 5   | 6   | 16  |
| 3   | 4   | 6   | 7   | 20  |
<!-- TBLFM: $5=($1+($2+($3+$4))) -->
JohannaTe commented 1 year ago

Fantastic! Thanks so much, works like a charm.

sbliven commented 5 months ago

Or even more concisely,

<!-- TBLFM: $5=sum($1..$4) -->